const b = [{index:5,name:"s5"}, {index:2,name:"s2"}, {index:3,name:"s3"}, {index:1,name:"s1"}, {index:8,name:"s8"}];
var a = [],
i; for (var i = 0; i < b.length; i++) {
var num = b[i].index;
a[num] = a[num]||{};
a[num] = b[i];
num == null;
} for (var i = 0; i < a.length; i++) {
if(a[i]) console.log(a[i].name);
}