Well, ["Title", "Ramones"]
is an array of strings. But [{"01":"Title", "02", "Ramones"}]
is an array of object.
If you are willing to push properties or value into one object, you need to access that object and then push data into that.
Example:
nietos[indexNumber].yourProperty=yourValue;
in real application:
nietos[0].02 = "Ramones";
If your array of object is already empty, make sure it has at least one object, or that object in which you are going to push data to.
Let's say, our array is myArray[]
, so this is now empty array, the JS engine does not know what type of data does it have, not string, not object, not number nothing. So, we are going to push an object (maybe empty object) into that array. myArray.push({})
, or myArray.push({""})
.
This will push an empty object into myArray
which will have an index number 0
, so your exact object is now myArray[0]
Then push property
and value
into that like this:
myArray[0].property = value;
//in your case:
myArray[0]["01"] = "value";
"02": "Ramones"
I assume? Also, in that case, why the array? Sounds like you want to construct a simple object – Cart