링크 조회 : 431
<SCRIPT>
var numArray=[0,21,1225,1247,11,1119,8];
document.write('numArray='+numArray+'<BR><BR>') // 배열변수 출력
function sortSame(a,a){ return a-a}; // 인수 a,a로 배열변수 정렬에 변화 없다.
document.write(numArray.sort(sortReverse)); // 기능함수 호출하여 출력
function sortNumbers(a,b){ return a-b}; // 인수 a,b로 배열변수를 오름차 순으로 정렬
document.write(numArray.sort(sortNumbers)+'<BR>'); // 기능함수 호출하여 출력
function sortReverse(b,a){ return a-b}; // 인수 b,a로 배열변수를 내림차 순으로 정렬
document.write(numArray.sort(sortReverse)); // 기능함수 호출하여 출력
</SCRIPT>
<SCRIPT>
function reverseSort(b,a){
if(a>b) return 1;
if(a<b) return -1;
return 0;
}
var numArray=[0,21,1225,1247,11,1119,8]
document.write(numArray+'<BR>');
document.write(numArray.sort(reverseSort));
</SCRIPT>
-----------=-------------
JS에서 배열을 소팅할 때 기능함수를 사용하여, 소팅 방법을 정할 수 있다.
| 제목 |
|---|
| [기본형] HTML (with 부트스트랩5.3 , jquery 3.7, vue.js) |
| 유용한 리눅스(LINUX) 명령어 |
| [공지] 기술 게시판 |
일 |
월 |
화 |
수 |
목 |
금 |
토 |
|---|---|---|---|---|---|---|
|
4.26
|
4.27
|
4.28
|
4.29
|
4.30
|
5.1
|
5.2
|
|
5.3
|
5.4
|
5.5
|
5.6
|
5.7
|
5.8
|
5.9
|
|
5.10
|
5.13
|
5.14
|
5.15
|
5.16
|
||
|
5.17
|
5.18
|
5.19
|
5.20
|
5.21
|
5.22
|
5.23
|
|
5.24
|
5.25
|
5.26
|
5.27
|
5.28
|
5.29
|
5.30
|
|
5.31
|
6.1
|
6.2
|
6.3
|
6.4
|
6.5
|
6.6
|