I have this response from a $.getJSON call. Now I want to select the name property of the object with "selected": true, and print it to a div with id charTitle.
"titles": [{
"id": 17,
"name": "Sergeant %s"
}, {
"id": 53,
"name": "%s, Champion of the Naaru"
}, {
"id": 64,
"name": "%s, Hand of A'dal",
"selected": true
}]
You can achieve this with a simple loop:
Example fiddle
Or with jQuery's
$.each():Note that if you have multiple objects in the array with
selectedset totrueyou would need to useappend()instead oftext()to set the content of thediv, otherwise the previous value will be overwritten.