我在创建包含较大数组的唯一子集的数组时遇到问题,请帮忙!
原阵
allMembers (6)[{},{},{},{},{},{}]
allMembers Payload: 0:{id:1, name: Alex} 1:{id:2, name: James} 2:{id:3, name: Bob} 3:{id:4, name: lara} 4:{id:5, name: Dan} 5:{id:6, name: Jes}
第二个数组
uniqueMembers (3)[{},{},{}]
uniqueMembers Payload: 0:{id:1, name: Alex} 1:{id:2, name: James} 2:{id:3, name: Bob}`
我正在寻找的是找到在allMembers
但不在的用户uniqueMembers
所以我想要的新数组输出将是以下数组resultArray
resultArray (3)[{},{},{}]
resultArray Payload: 0:{id:4, name: lara} 1:{id:5, name: Dan} 2:{id:6, name: Jes}
我的尝试
for(let m=0; m<allMembers.length;m++)
{
console.log('Testing include statement', uniqueMembers.includes(allMembers[m])) //output always false
if(uniqueMembers.includes(allMembers[m]))
{
console.log('ITS ALREADY IN: ', allMembers[m])
}else{
this.setState((prevState) => ({
resultArray: [...prevState.resultArray, allMembers[m]]
}));
console.log('ITS NOT IN: ', allMembers[m])
}
}// resultArray ends up the same as allMembers :(
任何有关如何获得所需resultArray值的反馈都将不胜感激!
潇潇雨雨
慕田峪4524236
胡说叔叔
相关分类