Tsea Tsea - 2 months ago 6
jQuery Question

How do I return object values in jquery

I'm not sure if its actually a object but that's what it says in the console.

I have a object that lookes like this

[{"id_no":"6798","name":"Annunication Of The Bvm","address1":"27335 N 8Th St "},
{"id_no":"6815","name":"Francis Of Paola ","address1":"21229 Conselyea St "}]


How do I display the value of "name" if a for loop. This is what I tried with no success

success:function(data){

console.log(data);
var pardata = JSON.stringify(data);

for(name in pardata) {
if(pardata.hasOwnProperty(name)) {
var value = pardata[name];
alert(value);
console.log(value);
}
}

}

Answer

Demo

var val=[{"id_no":"6798","name":"Annunication Of The Bvm","address1":"27335 N 8Th St "},
{"id_no":"6815","name":"Francis Of Paola  ","address1":"21229 Conselyea St "}]

$('button').click(function(){
  $.each(val,function(i,e){
    $('div').append('<p>'+e.name+'</p>');    
  });  
})