JavaScript push to array

前端 未结 5 1023
离开以前
离开以前 2020-12-07 20:12

How do I push new values to the following array?

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

I tried json.push(\"coolness\":\"

5条回答
  •  鱼传尺愫
    2020-12-07 20:57

    That is an object, not an array. So you would do:

    var json = { cool: 34.33, alsocool: 45454 };
    json.supercool = 3.14159;
    console.dir(json);
    

提交回复
热议问题