const objArr = [{ code: "aa", name: "11" }, { code: "bb", name: "22" }];const rlt = objArr.reduce((pre, cur) => { pre[cur.name] = [null]; return pre; //第一轮return的值,为第二轮的初始值}, {});console.log(rlt); //{ 11: [null], 22: [null] }复制代码
本文共 235 字,大约阅读时间需要 1 分钟。
const objArr = [{ code: "aa", name: "11" }, { code: "bb", name: "22" }];const rlt = objArr.reduce((pre, cur) => { pre[cur.name] = [null]; return pre; //第一轮return的值,为第二轮的初始值}, {});console.log(rlt); //{ 11: [null], 22: [null] }复制代码
转载地址:http://tivmx.baihongyu.com/