2012/01/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);
<< 정렬 결과 >>
[
,
,
,
,
]
간단하게 예제를 만들어봤다.
난 전혀 다른 곳을 파고 있었던 것이다.
'Web(HTML, CSS, JSP, JavaScript)' 카테고리의 다른 글
| JSON 데이터 정렬하기 (0) | 2012/01/26 |
|---|---|
| 클라이언트 측 객체 계층구조 (0) | 2011/09/16 |
| 전화번호 검증 스크립트(숫자만 입력 가능) (0) | 2011/08/16 |
| <article> 과 <section>의 차이점 (0) | 2011/04/18 |
| 090625_학습내용 : onkeyup 사용 + onkeypress 이벤트 사용하기 (0) | 2009/06/25 |
| API 이용하는 방법 링크 (0) | 2009/06/02 |
TAG javascript,
JSON,
sort