js求和
let data = [{
"goods_num": 3,
"goods_price": 1,
}, {
"goods_num": 10,
"goods_price": 1,
}, {
"goods_num": 4,
"goods_price": 1,
}];
let price = data.reduce((p, e) => p + e.goods_price * e.goods_num, 0);
console.log(price)
新数组:array;
原数组:list;
给原数组list的对象加一个名为aaaaa的属性,属性值为'11111'
然后打印 console.log(array); 即可看到需要的值
let list = [
{a:1},
{b:1},
{c:1}
];
let array=[];
list.map((item,index)=>{
array.push(
Object.assign({},item,{bbc:'11111'})
)
})
console.log(array);
网友评论