This is question
this is code of me
i have this response.
If I understand your problem, you need something like this
this is code of me
CodeCart(){This is my component.ts file and iam getting array of objects, i want to push an object "quantity" with value "0" in an array of obejcts.
let itemList= this.orderService.getCart()
let obj = {
quantity : 1
}
itemList.push(obj);
this.product = itemList
console.log("get products",this.product);
}
i have this response.
this.orderService.getCart() = [{id: 48, title: "Mango Juices", price: "30", category: "juices"}]Now, when I want to push me to get this result
0:{id: 48, title: "Mango Juices", price: "30", category: "juices"}This is answer
1:{quantity: 1}
If I understand your problem, you need something like this
ngOnInit() {
let itemList = [{ id: 48, title: "Mango Juices", price: "30", category: "juices" }]
itemList.forEach((key) => {
key["quantity"] = 0;
})
this.product = itemList
console.log("get products", this.product); //[{id: 48, title: "Mango Juices", price: "30", category: "juices", quantity: 0}]
}
No comments:
Post a Comment