Creates a new array with n
elements removed from the right.
Array.prototype.slice()
to remove the specified number of elements from the right.n
, to use a default value of 1
.const dropRight = (arr, n = 1) => arr.slice(0, -n);
dropRight([1, 2, 3]); // [1, 2]
dropRight([1, 2, 3], 2); // [1]
dropRight([1, 2, 3], 42); // []
JavaScript, Array
Removes elements from the end of an array until the passed function returns true
.
Returns the remaining elements in the array.
JavaScript, Array
Creates a new array with n
elements removed from the left.
JavaScript, Array
Creates an array with n
elements removed from the end.