The slice() method of an array returns part of the array in a new array (a shallow copy). An optional index number can be provided to show when to start copying and an optional index number can be provided to show when to stop copying. The original array is not modified.
const pets = ["dog", "bird", "fish", "duck", "cat"]
const result = pets.slice(2);
console.log(result);
// ["fish", "duck", "cat"]
const result1 = pets.slice(2, 4);
console.log(result1);
// ["fish", "duck"]
const result2 = pets.slice(1, 5);
console.log(result2);
// ["bird", "fish", "duck", "cat"]
const result3 = pets.slice(-2);
console.log(result3);
// ["duck", "cat"]
const result4 = pets.slice(2, -1);
console.log(result4);
// ["fish", "duck"]
const result5 = pets.slice();
console.log(result5);
// ["dog", "bird", "fish", "duck", "cat"]