rob.m rob.m - 3 years ago 111
Javascript Question

How to get objects data after an api call?

I am running the following:

var myTitle = "Battaglia di Forte Ṭabarsí";
var langList;
var url="|langlinks&noimages=true&mobileformat=true&page="+ myTitle + "&callback=?";
jQuery.each(data, function(i, item) {
langList = item.langlinks;

I can see the page has different languages and other properties that I can get when I use the parameter
in the api but then in the console I get:

(6) [Object, Object, Object, Object, Object, Object]

I would like to access that data, like title in another language and basically to be able to output any objects and more specifically any properties of each object.

Here it is a jsFiddle, check the console.

Answer Source

data is an object. It contains prase(property), which itself is an object, containing langLinks(property) : Array of objects

If you want to access langLinks items, use the index notation [ ] like so: langLinks[index] There is no need for jQuery.each(d... you can access specific language by filtering langLinks

data.parse.langlinks.filter(function(val){ return val.lang === 'en'});

When accessing object's proparties, use the dot or index notation (val.lang)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download