如何根据A数组将B数组组装为新数组?-灵析社区

我爱了你呢

let A = ['A', 'B', 'C'] let B = [ ['1A'], ['2A','2C'] ] 根据 A 数组将 B 数组组装一个新数组 newArr = [ ['1A', null, null], ['2A', null, '2C'] ] 我要的新数组 newArr = [ ['1A', null, null], ['2A', null, '2C'] ]

阅读量:15

点赞量:0

问AI
const conv = (schema, source) => source.map(a => { const dict = {} a.forEach(i => { const name = i.at(-1) // 没有给出具体的数据格式,假定和 A 匹配的字符串就是最后一位 dict[name] = i }) return schema.map(name => dict[name] ?? null) }) "image.png" (https://wmlx-new-image.oss-cn-shanghai.aliyuncs.com/images/20241030/2e74faca1a4d691bbfe9b5261ec7598a.png)