filmov
tv
array slice in javascript

Показать описание
The slice() method allows you to extract a portion of an array and create a new array with those extracted elements.
Here's an example:
const myArray = [1, 2, 3, 4, 5];
In this example, slice() extracts elements starting from index 1 (2nd element) up to, but not including, index 4 (5th element). The extracted elements are [2, 3, 4], which are then returned as a new array.
You can also omit the end index to slice until the end of the array:
const myArray = [1, 2, 3, 4, 5];
In this case, slice() extracts elements starting from index 2 (3rd element) till the end of the array.
The slice() method is handy when you need to work with a subset of an array without modifying the original array.