两个数组,A数组里对象的值,是B数组里对象的key

问题描述

let arr1 = [
  {abc:"name"},
  {abc:"content"}
]
let arr2 = [
  {0:"111",1:"222"},
  {0:"333",1:"444"}
]

你期待的结果是什么?

let arr3 = [
  {name:"111",content:"222"},
  {name:"333",content:"444"}
]
阅读 405
评论
    2 个回答
    • 1.9k
    const arr3 = arr2.map(i=>{
      const obj = {}
      for(var j in i){
        obj[arr1[j].abc]=i[j]
      }
      return obj
    })