0

I have a problem to add new object into an exist array. That's my code

var myArr = {"id1": {"name": "","post": ""}, "id2": {"name": "","post": ""}};
var nId = JSON.parse(['{"id3": {"name": "","post": "100"}}']);

myArr.push(nId);
console.log(myArr)

but return push not a function.

Please anyone can help me?
Thanks

Max
  • 1
  • You have an object, not an array. `push()` is a method of an array, not an object. To add a property to an object, simply provide it a name and set the value: `myArr.foo = nId;`. I would also suggest renaming `myArr`, because as mentioned above, it's not an array. – Rory McCrossan Jul 28 '21 at 18:17

0 Answers0