I am looping through a json object with the structure below:
var my_products = {
"products": [
{
"title": "Product 1",
"id": 001,
"stock_quantity": 0,
"in_stock": false
},
{
"title": "Product 2",
"id": 002,
"stock_quantity": 0,
"in_stock": false
},
{
"title": "Product 3",
"id": 003,
"stock_quantity": 1,
"in_stock": true
},
{
"title": "Product 4",
"id": 004,
"stock_quantity": 1,
"in_stock": true
}
]
};
I can loop through the object with the code below:
for(var i=0; i<my_products.products.length; i++) {
var product = my_products.products[i];
console.log(product);
console.log('in_stock:',product.in_stock);
}
Do you know how can I loop through each record where Products that have a "stock_quantity": 1 and "in_stock": true
properties?
In the example above there are 2 product records that have a "stock_quantity": 1
property(not zero quantity)