JQuery and JSON - Add element

Posted by Villager on Stack Overflow See other posts from Stack Overflow or by Villager
Published on 2010-05-27T13:27:28Z Indexed on 2010/05/27 13:31 UTC
Read the original article Hit count: 238

Filed under:
|

Hello,

I have a JSON variable defined as:

var myCollection = {
  "data": [
    { "name":"Joe", "id":"1" },
    { "name":"Bill", "id":"2" },
    { "name":"Dave", "id":"3" }
  ]
};

I have a JavaScript function that is responsible for adding items to the data element in myCollection. However, I'm not sure how to add a name/id pair to the collection via JavaScript. Can someone show me how to add to a JSON collection via JavaScript?

Thank you!

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JSON