im trying to sort an array with many object, but i can how to sort only the first value. this is my exemple code: https://jsfiddle.net/v6wc8ufg
Im trying to do the SQL order by value1, value2,value3
var myArray = [
{ id: 'a', val: '4', city: 'Spain' },
{ id: 'a', val: '1', city: 'Paris' },
{ id: 'z', val: '5', city: 'London' },
{ id: 'z', val: '4', city: 'Rome' },
{ id: 'b', val: '9', city: 'Italy' }
];
function SortByName(a, b) {
var aName = a.id;
var bName = b.id;
return aName < bName ? -1 : aName > bName ? 1 : 0;
}
myArray.sort(SortByName);