[英]Comparing two array of object to return values that are not found
I have two array of objects and I want to compare them and return values not found in the other我有两个对象数组,我想比较它们并返回在另一个对象中找不到的值
arr1 = [{ text: "Company", value: 1},{ text: "Project", value: 3},{
text: "Housing" value: 4}]
arr2 = [{ newCol: "SumAmount", existCol: "Amount"}, { newCol:
"SumProj", existCol: "Proj"}]
I am comparing newCol values in arr2 against text in arr1, so since SumAmount
and SumProj
are not in the text values of arr1 I should get SumAmount
and SumProj
我将 arr2 中的 newCol 值与 arr1 中的文本进行比较,因此由于SumAmount
和SumProj
不在 arr1 的文本值中,我应该得到SumAmount
和SumProj
Use filter
and some
使用filter
和some
arr1 = [{ text: "Company", value: 1},{ text: "Project", value: 3},{ text: "Housing",value: 4}] arr2 = [{ newCol: "SumAmount", existCol: "Amount"}, { newCol: "SumProj", existCol: "Proj"}] var res=arr2.filter(o=>.arr1.some(y=>y.text==o.newCol)) console.log(res)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.