so im using the etsy api with javascript calling this ajax code
$.ajax({ url: etsyURL, dataType: 'jsonp', success: function(data) {
that returns an object array i guess?
and goes into this .each function
if (data.ok) {
gallerySize=data.count;
$.each(data.results, function(i,item) { //assign array variables
shopName=item.Shop.shop_name;
what im trying to figure out- is what exactly the each function is doing- i dont understand where the ‘item’ object comes from and am trying to access information outside of the .each function
for example- as it is right now- shop_name only needs to be declared once, it doesnt make sense to have this code every single time inside the each method. Surely there is a way to access whatever object array the ajax function calls?
Im sure this is a rather simple thing- i just dont understand the way the .each statement it setup and where the item it refrences is coming from
In your code,
$.each()iterates throughdata.results.If it’s an array,
iis the index, anditemis the value at that index.If it’s an object,
iis the key, anditemis the value under that key.