我有两个数组(data 和 data_not_included)。这些数组的每个元素都有属性 ID 和名称。我这样填充它们:
data[i] = {
name :products.models[i].get('name'),
id : products.models[i].get('id')
};
现在我想显示数据中不在 data_not_included 数组中的元素。例如我有
data=[{name: Sugar}{id: 1},{name: Butter}{id: 2},{name: Cola}{id: 3}]
// and
data_nat_included = [{name: Sugar}{id: 1},{name: Butter}{id: 2}].
它应该{name: Cola}{id: 3}
只显示。
这是我已经做的:
for(var j=0;j<data_not_icluded.length;j++)
{
for(var i=0;i<data.length;i++)
{
if(data[i].id != data_not_icluded[j].id ){
//but this doesnt work for me it displayes a lot of element many times
}
}
}