Array 객체

메서드

설명

join()

배열 사이에 지정된 문자열을 추가합니다.

reverse()

배열을 역순으로 정렬합니다.

sort()

배열을 정렬합니다.

slice()

배열을 일부 선택합니다.

concat()

배열을 합칩니다.

shift()

첫 번째 배열을 가져오거나 제거합니다.

unshift()

첫 번째 배열을 추가합니다.

pop()

마지막 배열을 제거합니다.

const arr10 = [100, 200, 300, 400, 500];
        const arr20 = [600, 700, 800, 900, 1000];

document.write(arr10,"<br>");
document.write(arr10.join('*'),"<br>");
document.write(arr10.reverse(),"<br>");
document.write(arr10.sort(),"<br>");                            // 정렬하기
document.write(arr10.sort(function(a,b){return b - a}),"<br>"); // 순서 비교해서 더 큰 수를 앞으로 출력
document.write(arr10.sort(function(a,b){return a - b}),"<br>");
document.write(arr10.slice(1,3),"<br>");                        // [1]~[3]이전까지 출력
document.write(arr10.slice(2,3),"<br>");
document.write(arr10.concat(arr20),"<br>");                     // arr10, arr20 같이 출력
document.write(arr10.shift(),"<br>");                           // 맨 앞의 값을 가져옴
document.write(arr10,"<br>");                                   // shift의 기능때문에 100 삭제
document.write(arr10.unshift(100),"<br>");                      // 다시 100 넣음
document.write(arr10,"<br>");
document.write(arr10.pop(),"<br>");
document.write(arr10,"<br>");

/*
100,200,300,400,500
100*200*300*400*500
500,400,300,200,100
100,200,300,400,500
500,400,300,200,100
100,200,300,400,500
200,300
300
100,200,300,400,500,600,700,800,900,1000
100
200,300,400,500
5
100,200,300,400,500
500
100,200,300,400
*/

p.102 예제

p. 103 예제

Last updated

Was this helpful?