The problem of asking for help to jump out of the cycle

this.tableData.map((item,index) =>{
                  if ( item.discount !== 1 ) {
                    for (let index = 0; index < discountData.length; indexPP) {
                      if (item.discountId === discountData[index].id){
                        flag = true;
                      } 
                    }
                    if (!flag) {
                      item.discount = 2;
                      console.log("dsfdsf");
                    }
                  }
                });

to check whether there is any data stored in tabledata in discountdata, it is now written according to id matching, once the first few matches

if (item.discountId === discountData[index].id){
                        flag = true;
                      } 

after that, it will not continue. How should I change it

?
Mar.03,2021

Loop with forEach, and then use break, to jump out of the loop

this.tableData.forEach((item,index) =>{
      if ( item.discount !== 1 ) {
        for (let index = 0; index < discountData.length; indexPP) {
          if (item.discountId === discountData[index].id){
            flag = true;
            break;
          } 
        }
        if (!flag) {
          item.discount = 2;
          console.log("dsfdsf");
        }
    }
});

do not use map. Use foreach. Map cannot be jumped out

Menu