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
Use filter
and 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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.