【发布时间】:2018-08-22 09:56:28
【问题描述】:
我有一个这样的对象数组:
phoneContacts= [
{
firstName: "aaaa",
lasttName: "aaaa",
phoneNumbers: [{id: "1", label: "mobile", number: "09121111111"},{id: "1", label: "home", number: "02188888888"}]
},
{
firstName: "bbbb",
lasttName: "bbbb",
phoneNumbers: [{id: "1", label: "mobile", number: "09122222222"},{id: "1", label: "home", number: "02177777777"}],
},
...]
我想用这样的数组过滤它:
registeredUsers= [
{
ID: 1,
CellPhone: "09123333333"
},
{
ID: 2,
CellPhone: "09121111111"
},
...]
并返回:
contactsMergerdWithID= [
{
ID: 1,
firstName: "aaaa",
lasttName: "aaaa",
phoneNumbers: [{id: "1", label: "mobile", number: "09121111111"},{id: "1", label: "home", number: "02188888888"}]
},
{
ID: 0, // or without ID
firstName: "bbbb",
lasttName: "bbbb",
phoneNumbers: [{id: "1", label: "mobile", number: "09122222222"},{id: "1", label: "home", number: "02177777777"}]
},
...]
如果其中任何一个 mobilephoneNumbers 与第二个数组中的 CellPhone 匹配,我想在第二个数组中返回具有匹配 ID 字段的第一个数组。 我该怎么做?
【问题讨论】:
标签: javascript arrays object filter