Sort array

by DMINATOR

JavaScript

function WorkerValue() {
    this.value = null;
    this.index = 0;
}

var items = [];

var val = new WorkerValue();
val.value = "test";
val.index = 1;

items.push( val );

val = new WorkerValue();
val.value = "sdfdf";
val.index = 0;
items.push( val );

items.sort(function (a, b) {
                if (a.index < b.index)
                    return -1;
                if (a.index > b.index)
                    return 1;
                return 0;
});

alert( JSON.stringify(items));
// items is [ { name: 'Début' }, { name: 'Première