I am working with JSON data retrieved from an API and trying to figure out how to index an array inside an array using Nativescript.
JS: cart [{
JS: "_id": "5d3988cd287bad2943686920",
JS: "userid": "11E76234942299FCC13FFA163EDC2079",
JS: "products": [
JS: {
JS: "product_ID": "102",
JS: "price": 20,
JS: "quantiy": 2
JS: },
JS: {
JS: "product_ID": "103",
JS: "price": 20,
JS: "qty": 3
JS: },
JS: {
JS: "product_ID": "104",
JS: "price": 20,
JS: "qty": 3
JS: }
JS: ]
JS: }, {
JS: "_id": "5d399ec8f8514f2a9a68da30",
JS: "userid": "11E76234942299FCC13FFA163EDC2079",
JS: "products": [
JS: {
JS: "product_ID": "102",
JS: "price": 20,
JS: "qty": 3
JS: }
JS: ]
JS: }]
I need help with a function that will increment the quantity for each product:
incrementQty(product_ID) {
for (let i = 0; i < this.cart[i].products.length; i++) {
this.cart[i].products[i].qty++;
}
}
this.cart[i].products.length;
currently shows only 3 products.
The goal is to increment the quantity for each row in the array. How can I achieve this?