Skip to content

Instantly share code, notes, and snippets.

@tomblanchard
Last active August 29, 2015 14:01
Show Gist options
  • Save tomblanchard/50d0a8bde08b2716eb2b to your computer and use it in GitHub Desktop.
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.
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