Reverse sort json objects


I had a case that required taking the latest 10 articles and place them in descending order in a collection. To do this I needed to reverse insert the articles into my collection. The reason for this is that the API handed out the articles in ascending order, which I did not want.

The solution to reverse insert articles in my backboneJS collection.

var t = [];
for (var name in articles) {
   t[name] = articles[name];

var len = t.length;
while (len--) {
   if (t[len] !== undefined) {