Javascript
JSON 데이터 정렬하기
허니몬
2012. 1. 26. 17:53
JavaScript sort 참고 : http://www.w3schools.com/jsref/jsref_sort.asp
var testArray = [ {"id" : 1, "total" : 3}, {"id" : 2, "total" : 20}, {"id" : 3, "total" : 12}, {"id" : 4, "total" : 9}, {"id" : 3, "total" : 24} ]; function custonSort(a, b) { if(a.total == b.total){ return 0} return a.total > b.total ? 1 : -1; } testArray.sort(custonSort); console.log(testArray);
<< 정렬 결과 >>
[
,
,
,
,
]
간단하게 예제를 만들어봤다.
난 전혀 다른 곳을 파고 있었던 것이다.