Skip to content

Instantly share code, notes, and snippets.

@jeffersondev
Created December 28, 2017 00:16
Show Gist options
  • Select an option

  • Save jeffersondev/6d0fade965d0cec50afa347f5a309b44 to your computer and use it in GitHub Desktop.

Select an option

Save jeffersondev/6d0fade965d0cec50afa347f5a309b44 to your computer and use it in GitHub Desktop.
Exemplo de como percorrer um object com um array em javascript
function carregarDadosApi(url) {
$.getJSON(url, (retorno) => {
for (let i = 0; i < retorno.length; i++) {
const item = retorno[i]
$('#box').append('<div class="item-' + i + '"><h1>' + item.name + '</h1></div>')
for (let j = 0; j < item.images.length; j++) {
const image = item.images[j];
$('.item-' + i).append('<img src="' + image + '">')
}
if (item.price) {
$('.item-' + i).append('<div class="item--price">' + item.price.value + '</div>')
}
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment