Array.prototype.slicebeginnerconst arr = [10, 20, 30, 40, 50]
arr.slice(0, 3) // β [10, 20, 30]Use slice(0, n) to get the first n elements of an array as a new array.
arr.slice(0, n) returns the first n elements of the array. It is a clean, non-mutating alternative to manually trimming an array.
Challenge: Implement firstN(arr, n) that returns the first n elements using arr.slice(0, n).
firstN([1, 2, 3, 4, 5], 3) // β [1, 2, 3]
firstN([10, 20], 1) // β [10]