[英]getting the sizes of product in the cart
i have this code :我有这个代码:
if (action=="add"){
if(cart[productId]==undefined ){
cart[productId]={'quantity':1}
cart[productId]['size']=size
}
if (cart[productId]['size'] in array1){
cart[productId]['quantity']+=1
cart[productId]['size']=size
}
else{
console.log('the products '+cart.length+' '+cart[productId]["size"])
cart[productId]={'quantity':1}
cart[productId]['size']=size
}
}
this is an example of a cart这是一个购物车的例子
{
'1': { 'quantity': 1, 'size': 'XL' },
'3': { 'quantity': 3, 'size': 'L' }
}
and i want to make an array of all the sizes of an specific product in the array1我想在 array1 中创建一个包含特定产品的所有大小的数组
I Hope the following code will help you.我希望下面的代码对你有帮助。
var cart = {
'1': { 'quantity': 1, 'size': 'XL' },
'3': { 'quantity': 3, 'size': 'L' }
}, newCart=[];
newCart = Object.keys(cart).map((v)=>{
return cart[v].size;
});
console.log(newCart);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.