I have a single variable called $arrayQuantity
that holds a changing value. This value determines how many
item
arrays should be created within the $itemsContainer
array when the page is loaded.
For example:
//In this example, I want to create 3 `item` arrays inside the *itemsContainer* array.
//Each of these arrays will contain two dynamic values: `object_name` and `quantity`.
var object_name;
var quantity;
var item = [object_name, quantity];
var arrayQuantity = 3;
var itemsContainer = [];
//Below is an example of filling the array with dynamic data.
itemsContainer = [["Chair", "2"]["Table", "5"]["Glass", "8"]];
How should I go about solving this issue?
EDIT :
The dynamic data for object_name
and quantity
is determined based on which button is pressed on the screen (this information is not relevant to the question).
If the object_name
already exists within the array, only the quantity
should be updated in order to avoid duplicate entries of the same object_name
.