[자바스크립트] pop와 push, unshift와 shift

휘루·2023년 4월 12일
0

자바스크립트

목록 보기
16/40

pop(추가) / push(제거) (맨 끝 부분)

const target = ['가', '나', '다', '라'];

target.pop();

console.log(target);

pop을 쓰면 맨 끝 부분을 지울 수 있습니다.

const target = ['가', '나', '다', '라'];

target.push('마');

console.log(target);

push를 쓰면 마지막 부분을 새로 넣을 수 있습니다.

unshift(추가) / shift(제거) (맨 앞 부분)

shift로 제거가 가능합니다.

const target = ['가', '나', '다', '라', '마'];

target.shift();

console.log(target);

shift를 쓰면 맨 앞 글씨를 뺄 수 있습니다.

const target = ['가', '나', '다', '라', '마'];

target.unshift('무');

console.log(target);

unshift를 쓰면 맨 앞 글씨를 넣을 수도 있습니다.

즉 unshift(추가)와 shift(제거)가 앞쪽 컨트롤 pop(추가)과 push(제거)가 뒤쪽 컨트롤이 가능합니다.

profile
반가워요

0개의 댓글