我有两个这样的数组。第一个数组是
第二个是
customFields
,长度为2。var customFields = [
{
"$$hashKey":"object:259",
"fields":[
],
"id":0.84177744416334,
"inputType":"number",
"labelShown":"item",
"type":"textBox",
"value":"222222"
},
{
"$$hashKey":"object:260",
"fields":[
"as",
"dd",
"asd"
],
"id":0.51091342118417,
"inputType":"",
"labelShown":"labels",
"type":"selectBox",
"value":"dd"
}
]
第二个是
field
,长度为3。var field = [
{
"fields":[
],
"id":0.84177744416334,
"inputType":"number",
"labelShown":"item",
"type":"textBox"
},
{
"fields":[
"as",
"dd",
"asd"
],
"id":0.51091342118417,
"inputType":"",
"labelShown":"labels",
"type":"selectBox"
},
{
"fields":[
],
"id":0.32625015743856,
"inputType":"text",
"labelShown":"sample",
"type":"textBox"
}
]
这两个数组都是动态的,我需要通过 id
字段比较这些数组,并将缺失的对象从 field
数组添加到 customFields
数组中。如何在不使用嵌套循环的情况下完成这个操作?哪种方法最有效?谢谢!
_.merge
可以做到这一点,或者您可以与_.uniqBy
结合使用。 - emaniacs