TypeScript Angular 패스트 캠퍼스 강의 6일차

TypeScript Angular 패스트 캠퍼스 강의 6일차

splice

배열에서 시작인덱스로부터 몇개를 제거할지를 나타낸다.

splice 수행 후 원본배열에 저장된 값이 변한다.

console.clear(); const numbers= [10, 20, 30, 40, 50]; const index = numbers.indexOf(30); const spliced = numbers.splice( index, 1 ); // index(2) 번호를 시작으로 1개만 갖고오겠다. console.log(spliced); // [30] console.log(numbers); // [10, 20, 40, 50]

slice

배열에서 시작인덱스부터 끝인덱스까지의 부분 배열을 나타낸다.

slice 수행 후 원본배열에 저장된 값이 보존된다.

console.clear(); const numbers = [10, 20, 30, 40, 50]; const sliced = numbers.slice(0,2); // 시작: 0, 끝: 2 -> 인덱스 0,1 만 가져온다. console.log(sliced); // [10,20] console.log(numbers); // [10, 20, 30, 40, 50]

from http://ek12mv2.tistory.com/162 by ccl(A) rewrite - 2021-08-28 02:01:04