[😃, 🏀, 🍅, 🐵].slice(0, 2); 👉 [😃, 🏀]
/*
 * 주의하세요!
 * 배열에서 인덱스는 0부터 시작합니다.
 * 첫 번째 요소의 인덱스는 0이고, 두 번째 요소의 인덱스는 1입니다.
 */

// 배열을 만듭니다.
const colors = ["red", "green", "blue", "orange", "yellow"];

// 배열의 특정 범위의 요소를 추출하여 새로운 배열을 반환
const slicedColors = colors.slice(1, 3); // 1번 인덱스부터 3번 인덱스 직전까지

// 결과를 출력합니다.
console.log(slicedColors); // 출력: ['green', 'blue']

// 이때 원본 배열은 바뀌지 않습니다.
console.log(colors); // 출력: ['red', 'green', 'blue', 'orange', 'yellow']
arr.slice([start[, end]])
const numbers = [1, 2, 3, 4, 5];

// 배열의 처음 3개 요소를 추출합니다.
const firstThree = numbers.slice(0, 3);

console.log(firstThree); // 출력: [1, 2, 3]

// 배열의 마지막 2개 요소를 추출합니다.
const lastTwo = numbers.slice(-2);

console.log(lastTwo); // 출력: [4, 5]
const fruits = ["apple", "banana", "cherry", "date", "elderberry"];

console.log(fruits.slice(2, 4)); // ['cherry', 'date']
// 인덱스 2("cherry")부터 인덱스 4 이전("date")까지 추출하며, 인덱스 4의 요소는 제외됩니다.
const fruits2 = ["apple", "banana", "cherry", "date", "elderberry"];

console.log(fruits2.slice(2)); // ['cherry', 'date', 'elderberry']
// 인덱스 2("cherry")부터 배열의 끝까지 추출합니다.
const fruits3 = ["apple", "banana", "cherry", "date", "elderberry"];

console.log(fruits3.slice(-2)); // ['date', 'elderberry']
// 배열의 끝에서부터 2번째 요소부터 끝까지 추출합니다.
const fruits4 = ["apple", "banana", "cherry", "date", "elderberry"];

console.log(fruits4.slice(2, 4)); // ['cherry', 'date']

// 원본 배열은 그대로 유지됩니다.
console.log(fruits4); // ['apple', 'banana', 'cherry', 'date', 'elderberry']