JSFiddle - React, Tailwind, and code Playground
by Vitaliy
JavaScript
var list = [
{
id : 1,
text : 'item 1'
},
{
id : 5,
text : 'item 5'
},
{
id : 12,
text : 'item 12'
},
{
id : 2,
text : 'item 2'
},
{
id : 0,
text : 'item 0'
}
];
function renderList(list){
var ul = document.createElement('ul');
list.sort(function(a, b){
return a.id < b.id;
});
list.forEach(function(item){
var li = document.createElement('li');
li.setAttribute('data-id', item.id);
li.textContent = item.text;
ul.appendChild(li);
});
document.body.appendChild(ul);
}
renderList(list);