一个js数组匹配的问题

一个js数组匹配的问题

现在有两个数组:

moudlesArray = [

['a','b']

['c']

['d','e'],

['f'],

...

]

data = [

{name:'a'},

{name:'b'},

{name:'c'},

{name:'d'},

{name:'e'},

{name:'f'},

...

]

目标数组:

res = [

[{name:'a'},{name:'b'}],

[{name:'c'}],

[{name:'d'},{name:'e'}],

[{name:'f'}]

...

]


回答:

const dict = Object.fromEntries(data.map(obj => [ obj.name, obj ]))

moudlesArray.map(item => item.map(name => dict[name]))

不知道是不是顺序也一样,如果是的话

; (i => moudlesArray.map(item => item.map(() => data[i ++])))(0)

以上是 一个js数组匹配的问题 的全部内容, 来源链接: utcz.com/p/937592.html

回到顶部