检查 属性 数量是否 > 1 然后推送价格 * 数量

Check if property quantity is > 1 then push price * quantity

下面的函数循环遍历 var input 中对象的属性,例如

[{
    name: 'Nagellack 15 ml 2 2',
    id: '1057290002',
    price: '1.9',
    brand: 'a.o.n.',
    quantity: 1
}, {
    name: 'Ceramic Nail Lacquer 6 ml Coral Reef Coral Reef',
    id: '1027410001',
    price: '6.9',
    brand: 'Artdeco',
    quantity: 1
}]

并将新对象推入

products_list []

我正在尝试设置一个条件来检查对象的数量何时大于 1,然后将价格乘以数量。这里的问题是,尽管数量为 2,但我只获得了一种产品的价格。

我不知道代码中哪个地方设置条件最好。

function() {
    var input = {{dl_purchase_products}};
    var products_list = [];
        for(i=0;i<input.length;i++){
        products_list.push({
            id: input[i].id.slice(0,6),
            price: input[i].price,  <---- this should be the price for 2 
            quantity: input[i].quantity
        });
        }
    return products_list;
}

非常感谢!

此致, 安东

价格乘以数量。