Array without last element
Returns all the elements of an array except the last one.
- Use
Array.prototype.slice()
to return all but the last element of the array.
const initial = arr => arr.slice(0, -1); initial([1, 2, 3]); // [1, 2]
Returns all the elements of an array except the last one.
Array.prototype.slice()
to return all but the last element of the array.const initial = arr => arr.slice(0, -1); initial([1, 2, 3]); // [1, 2]
Array destructuring can be leveraged in many different ways. Here's one of them.
Learn how to execute a function for each element of an array, starting from the last one.
Group array elements into two or more arrays arrays, depending on the provided function's return value.
Learn how to check if an array has one or more values matching the given function, and how to find the matching elements.