从一个数组对象中取key 和value组成一个新的对象
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'}