I am trying to populate a JavaScript array by using the push method to add individual elements.
I have successfully created the array like this:
Initializing the array:
var buildProduction = new Array();
Then, I define and add each element to the array using push:
var singleString = {step: 1, name: sName.value, description: sDescription.value, lon: sLon.value, lat: sLat.value, ficon: sIcon.value, img: filePathName}
buildProduction.push(singleString)
I repeat this process with different data, resulting in an array like this:
[
{step: 1, name: sName.value, descri...},
{step: 2, name: sName.value, descri...},
{step: 3, name: sName.value, descri...},
{step: 4, name: sName.value, descri...},
{step: 5, name: sName.value, descri...},
{step: 6, name: sName.value, descri...}
]
However, I would like to group these arrays under specific names, like this:
"ExampleName":[
{step: 1, name: sName.value, descri...},
{step: 2, name: sName.value, descri...},
{step: 3, name: sName.value, descri...},
{step: 4, name: sName.value, descri...},
{step: 5, name: sName.value, descri...},
{step: 6, name: sName.value, descri...}
]
Unfortunately, I am unsure of how to achieve this using push or any other method...
The solution is likely simple and may have been addressed elsewhere, but I am struggling to find the right search terms.