자바스크립트-splice함수와 slice함수
·
Language/JavaScript
splice함수로 기존 원본 배열의 요소를 제거할 수 있다. const numbers = [10, 20, 30, 40]; const index = numbers.indexOf(30); // index부터 시작해서 하나 제거하겠다. numbers.splice(index,1); console.log(numbers); //결과는 [10,20,40] 또는 제거한 요소를 변수에도 담을 수 있다. const numbers = [10, 20, 30, 40]; const index = numbers.indexOf(30); const spliced = numbers.splice(index,2) console.log(spliced); //결과는 [30,40] 기존의 배열을 변경하지 않고 해당 인덱스부터의 요소를 꺼내오는 ..
takoyummy
'splice' 태그의 글 목록