jquery - Getting "undefined" from a javascript array in .each loop -


i've seen number of similar questions posted none of them have been able me closer solution.

i have data coming in me ecommerce api: (keep in mind, have no control on how data being sent me can't change @ "source.")

object { url: "http://pathtomyimage.jpg", name: ""} name: ""url:  "http://pathtomyimage.jpg"  __proto__: object__definegetter__: __definegetter__() { [native code] }__definesetter__: __definesetter__() { [native code] }__lookupgetter__: __lookupgetter__() { [native code] }__lookupsetter__: __lookupsetter__() { [native code] }constructor: object() { [native code] }hasownproperty: hasownproperty() { [native code] }isprototypeof: isprototypeof() { [native code] }propertyisenumerable: propertyisenumerable() { [native code] }tolocalestring: tolocalestring() { [native code] }tostring: tostring() { [native code] }valueof: valueof() { [native code] }get __proto__: __proto__() { [native code] }set __proto__: __proto__() { [native code] } 

these images loop through on .each statement , url. frankly don't know proto stuff is? i'm not interested in outputting of it.

this i'm doing:

$(data.images).each(function(index, value) {  console.log(this.url); // outputting array see above   }); 

i'm getting url i'm getting "undefined" breaking image if try in .each loop...

$(data.images).each(function(index, value) { $('#mycontainer').append("<img src='" + this.url + "'>"); }); 

thanks in advance suggestions , help.

edit - asked post entire string. if console.log(data) get. it's huge array of... well, stuff. did not expand open every object believe give idea of structure of entire object. before trying pair down having trouble if believe entire string help, here is.

object     availability: objectcode: "m"__proto__: object__definegetter__: __definegetter__() { [native code] }__definesetter__: __definesetter__() { [native code] }__lookupgetter__: __lookupgetter__() { [native code] }__lookupsetter__: __lookupsetter__() { [native code] }constructor: object() { [native code] }hasownproperty: hasownproperty() { [native code] }isprototypeof: isprototypeof() { [native code] }propertyisenumerable: propertyisenumerable() { [native code] }tolocalestring: tolocalestring() { [native code] }tostring: tostring() { [native code] }valueof: valueof() { [native code] }get __proto__: __proto__() { [native code] }set __proto__: __proto__() { [native code] }      averagedealermargin: "0.50"     currency: "usd"     customfields: array[0]     image: "http://pathtoaimage.jpg"     // here's trouble maker...     images: array[2]0: objectname: ""url: "http://pathtoanotherimage.jpg"__proto__: object1: array[0]length: 2__proto__: array[0]     locale: "en-us"     name: "productname"     partnumber: "700"     price: "19.99"     pricedisplay: "$19.99"     shippingmethod: "3"     weight: object         units: "lb"          value: "1.8" __proto__: object__proto__: object 

apologies if wasn't totally clear before, appreciate assistance here. i've been banging head on 1 2 days on , off.

one more edit... 1 answer on here did click didn't consider absence of return on function. expand further on how i'm pulling on data using functions because i'm checking first product i'm referencing legit. shopatron api fwiw, documentation has been, lacking, nice way put it... anyway you'll see reference @ top of script so:

var partnumber = '<?php echo $productid; ?>';     $(document).ready(function() {         shopatron.getproduct({             partnumber: partnumber         },{             success: function(p) {                 outputproductname(p);                 outputproductimage(p);                 outputproductadditionalimages(p);                 outputproductprice(p);                 outputdescription(p);                 outputspecs(p);             },             templatefriendly : false                                         }     ); 

now function down below follows:

function outputproductadditionalimages(data) {     $('#mycontainer').append("<img src='" + this.url + "'>"); }); 

try using $.each way:

$.each(data.images, function(i, obj) {     if (obj.url) {         $('#mycontainer').append("<img src='" + obj.url + "'>");     } }); 

see if trick.


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -