-3

I have an object like below:

var data = [
  {item_name: 'Book', stock: 15},
  {item_name: 'Pencil', stock: 15},
  {item_name: 'Paper', stock: 3}
];

And then i generate a list with HTML from the object:

console.log(data);
var html = '';
for (var i = 0; i < data.length; i++) {
    html += '<li class="list-group-item" id="listGroup">'+data[i].item_name+'<span class="badge">'+data[i].stock+'</span></li>';
}
$('#listItem').html(html);

If i add new object, how do i put the new object at the beginning of the list ?

metaphor
  • 470
  • 4
  • 13
  • 27
  • 2
    `data` is an array not an object – Weedoze Jan 23 '17 at 13:50