mahdi pishguy mahdi pishguy - 1 month ago 7
Javascript Question

Nodejs Parsing nested json array

this is simple code which i want to parse

values
json array and print data from that,

var data = {
"mobileNumber": "3",
"userContacts": {
"values": [{
"nameValuePairs": {
"contactName": "aaaaa",
"contactPhone": "111111"
}
}, {
"nameValuePairs": {
"contactName": "bbbbb",
"contactPhone": "222222"
}
}]
}
};

var jsonArray = JSON.parse(data.userContacts.values);

for (var i=0; i<jsonArray['values'].length; i++){

//print contactName and contactPhone from nameValuePairs

}


i created this link on
jsFiddle
to test that

Answer

Or just :

data.userContacts.values.forEach(x => {
  console.log(x.nameValuePairs.contactName, x.nameValuePairs.contactPhone);
});
// aaaaa 111111
// bbbbb 222222
Comments