数组中的某一项转化成对象

const arr = [
  {
    id: 1,
    name: '再改下试试',
    key: "statistic.management"
  },
  {
    id: 2,
    name: '再改下试试',
    key: "statistic.home"
  }
];

const object = arr.reduce((acc, curr) => {
  acc[curr.key] = true;
  return acc;
}, {});

console.log(object);
// 输出: {"statistic.management": true, "statistic.home": true}

你可能感兴趣的:(前端,javascript,vue.js)