Created
December 28, 2017 00:16
-
-
Save jeffersondev/6d0fade965d0cec50afa347f5a309b44 to your computer and use it in GitHub Desktop.
Exemplo de como percorrer um object com um array em javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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