Array.prototype.slice()
Array.prototype.slice() is a JavaScript method in the Array category. Returns a shallow copy of a portion of an array. The syntax is array.slice(start, end). It returns a new array containing the extracted elements. A typical example: [1, 2, 3, 4].slice(1, 3) // [2, 3]. Another practical use — Copy an array: const original = [1, 2, 3] const copy = original.slice() console.log(copy) // [1, 2, 3] console.log(copy === original) // false Its time complexity is O(n), which matters when it runs over large inputs. The TypeScript signature is (start?: number, end?: number): T[]. A close sibling is Array.prototype.map(), which creates a new array populated with the results of calling a provided function on every element. A close sibling is Array.prototype.filter(), which creates a new array with all elements that pass the test implemented by the provided function. A close sibling is Array.prototype.reduce(), which executes a reducer function on each element, resulting in a single output value.