let fruitarr = {
{fruitId:201,channel:11},
{fruitId:202,channel:2},
{fruitId:203,channel:13},
{fruitId:201,channel:4},
{fruitId:202,channel:4},
}
fruitparams:{
201:'11,4',
202:'2,4',
203:'13'
}
如何根据水果的id,做统计js拼装
let fruitarr = {
{fruitId:201,channel:11},
{fruitId:202,channel:2},
{fruitId:203,channel:13},
{fruitId:201,channel:4},
{fruitId:202,channel:4},
}
fruitparams:{
201:'11,4',
202:'2,4',
203:'13'
}
如何根据水果的id,做统计js拼装
假如 fruitarr
是 Array
的话
let fruitparams = {}
fruitarr.forEach(item => {
if(fruitparams[item.fruitId]){
fruitparams[item.fruitId] += `,${item.channel}`
}else{
fruitparams[item.fruitId] = `${item.channel}`
}
})
6 回答3k 阅读✓ 已解决
8 回答4.8k 阅读✓ 已解决
6 回答3.5k 阅读✓ 已解决
5 回答2.9k 阅读✓ 已解决
6 回答2.4k 阅读
5 回答6.4k 阅读✓ 已解决
4 回答2.3k 阅读✓ 已解决