Last active
August 29, 2015 14:01
-
-
Save tomblanchard/50d0a8bde08b2716eb2b to your computer and use it in GitHub Desktop.
Array of objects `for` loop with repaint performance in mind, mostly for use in fetching and displaying data from external JSON APIs.
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
var data = [ | |
{ | |
id: 1, | |
name: 'One', | |
image: 'http://image-1.jpg' | |
}, | |
{ | |
id: 2, | |
name: 'Two', | |
image: 'http://image-2.jpg' | |
} | |
]; | |
var html = ''; | |
for (var i = 0, len = data.length; i < len ; i++) { | |
html += [ | |
'<ul>', | |
'<li>' + data[i].id + '</li>', | |
'<li>' + data[i].name + '</li>', | |
'<li>' + data[i].image + '</li>', | |
'</ul>' | |
].join(''); | |
} | |
document.querySelector('body').innerHTML += html; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment