[jQuery] need some basic json object help
I've gotten to be fairly intermediate at consuming json objects, such
as those I'm retrieving from web api's. However, I'm trying to push
the boundaries of what I understand about JSON objects once the client
has loaded them. I have been searching around google for the last
couple of hours for what I think I want to know but I'm getting
nowhere. Hoping some other js wizzes can help me out. This isn't
directly a jQuery question, but I need to understand more about this
to help me write better jQuery code.
This is my sample data for the following questions:
var obj = { "nodes" :[
{
type : 'a',
name : 'stuff'
},
{type : 'b'},
{type : 'c'}
]
};
1) How can I add new nodes to an existing object? I can reference
obj.nodes[x].type for example. Now I want to add a new type to
"nodes". I tried: obj += {type:'d'}; but got nothing usable. Except
that obj.nodes.length went from 3 to 62.
2) Is there a list of core Javascript methods that let you work with
JSON objects? Something like .push, .pop, etc?
3) How do you search a JSON object? Suppose I want to find a group of
nodes that all have the name "stuff", regardless of what their "type"
property is?
I know I can loop through an object using for(i in obj){}.