[英]JS find matching object from array in object
I have an array:我有一个数组:
let gid = ['554', '555', '564', '575', '618']
Then I have an object:然后我有一个 object:
let obj = {
attr1: 'att',
attr2: 'att2',
attr3: [
{
attr: 'att',
id: 554,
},
{
attr: 'att',
id: 555,
},
{
attr: 'att',
id: 1,
},
],
};
How to I return the values of obj.attr3.id
that match the values in gid
?如何返回与
gid
中的值匹配的obj.attr3.id
的值?
you should map the attr3 array.你应该 map attr3 数组。
let matches = obj.attr3.map( (item, index) => item.id == gid[index])
Is this what you might be asking for?这是你可能要求的吗?
obj.attr3.filter((item, index) => item.id == gid[index])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.