2014년 6월 13일 금요일

JavaScript key, value Array Sort

var points = [40, 100, 1, 5, 25, 10];
points.sort(function(a, b){return b-a});

var status = new Array();
status.push({name: 'BOB', val: 10});
status.push({name: 'TOM', val: 3});
status.push({name: 'ROB', val: 22});
status.push({name: 'JON', val: 7});
status.sort(function(a,b) {
    return a.val - b.val;
});



http://www.w3schools.com/jsref/jsref_sort.asp
http://stackoverflow.com/questions/12788051/how-to-sort-an-associative-array-by-value

댓글 없음:

댓글 쓰기