const array1
= [
{currency
: 'CNY', value
: 1 },
{currency
: 'USD', value
: 2 }
]
const array2
= [
{currency
: 'CNY', value
: 332 },
{currency
: 'USD', value
: 424 },
{currency
: 'HK', value
: 123 }
]
数组array1 和 array2,现在需要根据array1子元素的currency字段,删除array2中多余的子元素, 即得到
const array2
= [
{currency
: 'CNY', value
: 332 },
{currency
: 'USD', value
: 424 }
]
解决方案
let result
= array2
.filter(item
=> array1
.some(value
=> value
.currency
== item
.currency
))
转载请注明原文地址:https://ipadbbs.8miu.com/read-42189.html