The problem of nesting traversal of two for loops

the length of discountData is greater than the length of tabaleData

if you want to compare the value of discountId of tabaleData with that of discountData, if it is not equal to handle it (tableData does not contain data of discountData)

now no matter how to change it, it contains data that wants to know what went wrong

Mar.03,2021

tableData does not contain discountData data
to determine whether one item in an array is in the other, you have to traverse until at least the last one to know that it does not exist.
you trigger

every time you compare.
for (let index = 0; index < this.tableData.length; indexPP) {
    flag = false;
    for (let i = 0; i < discountData.length; iPP) {
        if (this.tableData[index].discountId == discountData[i].id) flag = true
    }
    if (flag) {
        //
    } else {
        //
    }
}
this.tableData.forEach(v=>{
    if(discountData.some(k=>v.discountId==k.id)){
        //
    }else{
        //
    }
})

replace it with! =?


now no matter how it is changed, it is processed with the data contained
< H2 > simulate the data: < / H2 >
let tableDate = [{discountId:2,discount:1}];
let discountDate = [
    {
        id:1
    },
    {
        id:2
    }
];

then in the first round of comparison, we find tableDate [0] .discountId! = = discountDate [0] .id , so tableDate [0] .compare = 2 . That's not what you want, is it?

< H2 > solve pseudo code: < / H2 >
let disCountData = res.data;
this.tableData.forEach(function(item,index){
  let flag= false;
  disCountData.forEach(function(data,i){
    if(item.discuntId === data.id){
      return flag  = true;
    }
  })
  if(!flag){
    item.discount = 2;
  }
})
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3e792-2bc6c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3e792-2bc6c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?