javascript - How to get objects data after an api call? -
i running following:
var mytitle = "battaglia di forte Ṭabarsí"; var langlist; var url="https://it.wikipedia.org/w/api.php?action=parse&disablelimitreport=true&format=json&prop=text|langlinks&noimages=true&mobileformat=true&page="+ mytitle + "&callback=?"; $.getjson(url,function(data){ jquery.each(data, function(i, item) { langlist = item.langlinks; }); console.log(langlist); });
i can see page has different languages , other properties can when use parameter langlinks
in api in console get:
(6) [object, object, object, object, object, object]
i access data, title in language , able output objects , more properties of each object.
here jsfiddle, check console.
data
object
. contains prase
(property
), object
, containing langlinks
(property
) : array
of objects
if want access langlinks
items, use index notation [ ]
so: langlinks[index]
there no need jquery.each(d...
can access specific language filtering langlinks
data.parse.langlinks.filter(function(val){ return val.lang === 'en'});
when accessing object's proparties, use dot or index notation (val.lang
)
Comments
Post a Comment