-2
When I try to run the loop, even if I want to enter the is, I already checked and the array with the object is not empty, but does not execute the loop... Any idea?
var caminho = [];
$.get("http://localhost/crocs/arquivo.json", function(data) {
data = typeof data == 'string' ? JSON.parse(data) : data;
data.forEach(function(elementoDaArray) {
skuid = elementoDaArray.SkuId;
valor = elementoDaArray.Valor;
letra = elementoDaArray.Letra;
imagem = elementoDaArray.Imagem;
caminho.push({
img: imagem,
id: skuid
})
});
});
for (var i = 0; i < caminho.length; i++) {
console.log(products[i].img);
}
can put an example of the value of
data
?– Ricardo Pontual
{"Skuid":"331","Value":"9.90","Letter":"A","Image":"10006994_001UNI"} this is the json that returns through $.get
– Luiz Flávio
Luiz he is a simple object not an array, so the
forEach
won’t work– Ricardo Pontual
Try, before the
forEach
run this for you to see:skuid = data.SkuId;
– Ricardo Pontual