ar em ar em - 4 years ago 143
Ajax Question

AJAX: How to get array on multi dimensional array

I have a json which is . I just want to get specific data which is

obj['contacts']['name']


How can i get

obj['contacts']['name']


name on Contacts array

enter image description here

This is my code:

$.ajax({
type: 'GET',
dataType: 'json',
url: uri,
cache: false,
contentType: 'application/json',
success: function(data) {
for (var obj in data) {
console.log(obj['contacts']['name']);
}
}
});

Answer Source

In your case this is how you want get name from contacts

$.ajax({
  type: 'GET',
  dataType: 'json',
  url: uri,
  cache: false,
  contentType: 'application/json',
  success: function(data) {
    if (!data.contacts) return;
    var names = data.contacts.map(function(dt) {
      return dt.name;
    });
    console.log(names);
  }
});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download