在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ es6語法數(shù)組轉(zhuǎn)換?

es6語法數(shù)組轉(zhuǎn)換?

const customer = [
  {id: 1, count: 2},
  {id: 2, count: 89},
  {id: 3, count: 1}
];

轉(zhuǎn)換成:

const customer = [
  {type:'id',value:[1,2,3]},
  {type:'count',value:[2,89,1]},
];

//customer是動(dòng)態(tài)數(shù)據(jù),id和count并不是固定的

解決方案可參考sxlwar回答內(nèi)他的評(píng)論。

回答
編輯回答
陪她鬧
const result = customer.reduce((acc,cur) => {
    acc[0].id.push(cur.id);

    acc[1].count.push(cur.count);
    
    return acc;
},[{id: []}, {count: []}]);
2017年11月8日 02:26