Comparing two objects taken arrays deleted and the new array

//原数据
let oldArr = [
{faqId: 1, faqName: null}, {faqId: 2, faqName: null}, {faqId: 3, faqName: null}, {faqId: 4, faqName: null},{faqId: 5, faqName: null}]
// delete the new data over the data 
the let newArr =
[ {faqId: 2, faqName: null}, {faqId:. 4, faqName: null}, {faqId:. 6, faqName: null} , {faqId:. 8, faqName : null} ]

let NewIdArr = newArr.map((e) => e.faqId); Let oldIdArr oldArr.map (= (e) => e.faqId); let addIdArr = NewIdArr.filter ((i) => { return oldIdArr.indexOf(i) === -1; }); // add the last data faqId Let delIdArr = oldIdArr.filter ((i) => { return NewIdArr.indexOf(i) === -1; }); // finally deleted data faqId = addFaqList the let [];
      // Returns an array of the object based on the id add, delete empathy this.rowSelection.selectedRows.forEach((e) => { addIdArr.forEach((ele) => { if (e.faqId === ele) { addFaqList.push(e); } }); });

 

Guess you like

Origin www.cnblogs.com/yhhBKY/p/12376108.html