Seeking guidance on manipulating data within an associative array.
My Objective
I am looking to confirm the existence of an order in the sellingItems list.
Background Information
The goal is to determine if an order exists so that we can provide the current inventory count as a response.
The Query
I need to validate the presence of specific data (order) in an associative array and compute the stock quantity.
public calculateStockQuantity(itemInstances) {
const stockQuantity = //We want to count the number of items in stock. In this case, we want it to be 2 (calculated based on whether the data exists in sellingItem.order or not).)
return stockQuantity;
}
List of Targeted Associative Arrays
//There are three itemInstances for one product because the number of products sold is three.
itemInstances =
[
{
"id": "1",
"sellingItem": [
{
"id": 1,
"price": 3000,
"orderedItem": [
{
"id": 1
"ordered_at": "2021-04-01 10:00:00"
}
]
}
]
},
{
"id": "2",
"sellingItem": [
{
"id": 2,
"price": 3000,
"orderedItem": []
}
]
},
{
"id": "2",
"sellingItem": [
{
"id"": 2,
"price": 3000,
"orderedItem": []
}
]
}
]
Please excuse my amateurish query.