자바스크립트 배열 슬라이스()
예
요소 선택:
const fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
const citrus = fruits.slice(1, 3);
음수 값을 사용하여 요소 선택:
const fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
const myBest = fruits.slice(-3, -1);
정의 및 사용
이 slice()
메서드는 배열에서 선택한 요소를 새 배열로 반환합니다.
이 slice()
방법은 주어진 시작 에서 주어진 끝 (포함하지 않음)까지 선택 합니다.
이 slice()
방법은 원래 배열을 변경하지 않습니다.
통사론
array.slice(start, end)
매개변수
Parameter | Description |
start | Optional. Start position. Default is 0. Negative numbers select from the end of the array. |
end | Optional. End position. Default is last element. Negative numbers select from the end of the array. |
반환 값
선택한 요소를 포함하는 새 배열입니다. |
브라우저 지원
slice()
ECMAScript1(ES1) 기능입니다.
ES1(JavaScript 1997)은 모든 브라우저에서 완벽하게 지원됩니다.
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |