记住用户名密码
const type = [ { amount: '', size: '4013' }, { amount: '1', size: '1613' }, { amount: '5', size: '2007' }, { amount: '9', size: '3613' }, { amount: '', size: '2413' }, { amount: '10', size: '1213' }, { amount: '', size: '3213' }, { amount: '11', size: '2013' }, { amount: '', size: '0807' }, { amount: '', size: '2807' }, { amount: '6', size: '1607' } ]
let newArr={}; type .map(itm=>{ newArr[itm.size] = itm.amount }) console.log('1',newArr) {1213: '10', 1607: '6', 1613: '1', 2007: '5', 2013: '11', 2413: '', 2807: '', 3213: '', 3613: '9', 4013: '', 0807: ''}
tips:去掉里面的空值
let newArr={}; type .map(itm=>{ if (itm.amount) { newArr[itm.size] = itm.amount } }) console.log('1',newArr) {1213: '10', 1607: '6', 1613: '1', 2007: '5', 2013: '11', 3613: '9'}
目前有 0 条留言 其中:访客:0 条, 博主:0 条