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

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}

猜你喜欢

转载自blog.csdn.net/LRQQHM/article/details/131793099