Jack Jack - 8 months ago 82
JSON Question

JavaScript push to array

How do I push new values to the following array?

json = {"cool":"34.33","alsocool":"45454"}

I tried
, but it didn't work.


It's not an array.

var json = {"cool":"34.33","alsocool":"45454"};
json.coolness = 34.33;


var json = {"cool":"34.33","alsocool":"45454"};
json['coolness'] = 34.33;

you could do it as an array, but it would be a different syntax (and this is almost certainly not what you want)

var json = [{"cool":"34.33"},{"alsocool":"45454"}];

Note that this variable name is highly misleading, as there is no JSON here. I would name it something else.