sort(fnc(a, b{}return a-b)) + reverse() 내림차순
let array = [52, 71, 32, 103, 273, 93]
array.sort(function (a, b) {return a - b})
document.write(array.reverse()); //273,103,93,71,52,32
https://standout.tistory.com/611
sort(fnc(a, b{}return a-b)) 오름차순
sort(fnc(a, b{}return a-b)) 오름차순 let array = [52, 71, 32, 103, 273, 93] array.sort(function (a, b) {return a - b}) document.write(array); //32,52,71,93,103,273
standout.tistory.com
'JavaScript' 카테고리의 다른 글
| for of 과 for in의 차이 (0) | 2023.05.10 |
|---|---|
| Math.min/max 최소값, 최대값 구하기 (0) | 2023.05.10 |
| sort(fnc(a, b{}return a-b)) 오름차순 (0) | 2023.05.10 |
| reverse() 역순정렬 (0) | 2023.05.10 |
| 자바스크립트에서 ${contextPath} 변수로 사용하기 (0) | 2023.04.12 |