I have the following JSON structure on "y" location:
{"results":[{
"a_id":4529245,
"type":"a",
"name":"HONDA"
},{
"a_id":1234567,
"type":"l",
"name":"Autos Marron"
}]}
Inside my JS document I have the following code:
var i;
i=0;
$.getJSON('/document/location', function( data ) {
console.log(data);
$.each( data, function( key, val ) {
var contentString = '<span>'+
val[i].name +
'</span>';
$('#info').append(contentString);
i++;
});
});
I searched online and I readed that I would be able to do val.name and would be able to print each of the "name" variables inside my JSON document.
But I have to use a incrementing variable (i) in order to print only the first variable that equals to "HONDA" using val[i].name
I'd like to print all variables called name. What am I doing wrong?
Thanks in advance
hondaor all the values of 'name' attribute ?