Javascript - Data Processing

//equivalent to calling the same interface three times with different parameters, 
let arr1 = [];
newArray.forEach((v, index) => {
  let sqlParams = `select * from alarm_center_info where 1=1 and model_name = '${v.newModel}' and period_time <= '${v.newTime}' and period_time > '${v.minTime}'`;
arr1[index] = req(sqlParams);
});
let firstData = [];
let secondData = [];
let threedData = [];
Promise.all(arr1).then(function(data) {
  //data return array object [0:{...},1:{..},2:{..}]
  //distinguish three different types of data based on a specific field in the object 
  data.forEach(item => {
     if (item.rows.length !== 0) {
      item.rows.forEach(v => {
        if (
          v.model_name == 'first' 
        ) {
          firstData.push(v);
        } else if (
          v.model_name == 'tow' 
        ) {
          secondData.push(v);
        } else if (v.model_name == 'three') {
          threedData.push(v);
        }
      });
    }
  })
console.log(firstData, 'three different types of data', secondData,  threedData);
//return results [{object},{object},{object}.....],[{object}....],[{object},{object}.....]
     function findDuplicateObjects(arr) {
    //based on a specific field within each object( min_name )determine if there is duplicate data 
    let newArr = [];
    arr.forEach(item => {
//findIndex the () method returns the position of the first element of an array that meets the passed test condition (function). call the function once for each element in the array to execute 
//when the elements in the array are tested under certain conditions, return true when, findIndex () returns the index position of the element that meets the criteria, and subsequent values will not be called to execute the function. 
//if there are no eligible elements, return -1 
      let newArrIndex = newArr.findIndex(v => v.name === item.min_name);
      if (newArrIndex === -1) {
        let newArrObj = arr.filter(v => v.name == item.min_name);
        newArr.push({ name: item.min_name, value: newArrObj });
        
      }
    });
    return newArr;
  }
  let oneRepeatList = findDuplicateObjects(firstData);
  let towRepeatList = findDuplicateObjects(secondData);
  let threeRepeatList = findDuplicateObjects(threedData);
  console.log(oneRepeatList,towRepeatList, threeRepeatList, '1111',);
  //return results :oneRepeatList:[
   { name:'1',value:[ { id:'1',name:'1',time:'2023-12-09'},{ id:'2',name:'1',time:'2023-01-09'},{},{},{}.....]},
   {{ name:'2',value:[ { id:'0021',name:'1',time:'2023-10-09'},{ id:'2',name:'1',time:'2023-01-09'},{},{},{}.....},
   {{ name:'3',value:[ { id:'3331',name:'1',time:'2023-12-09'},{ id:'3332',name:'1',time:'2023-06-09'},{},{},{}.....}
   .... 
   ]
 


  
  
})