javascript
Lodash - Get all elements of array except the last one
To get all elements from an array except the last one or to remove last element from the array using lodash, you can use _.initial() method of lodash
const arr = [10, 20, 30, 40, 50];
const result = _.initial(arr);
// => [10,20,30,40]
In the code snippet, we have an array arr and we want to get all elements of it except the last one. We are doing that using the .initial() method of lodash.
_.initial Lodash
_.initial(Array)
Parameters description
Array: [Required] The array whose elements you want to get except the last one.
Was this helpful?
Similar Posts
- Remove last n elements from an array using Lodash
- Lodash - Get the last element of an array
- Get all values from an array which does not exist in other array Lodash
- Remove first n elements from an array using Lodash
- Lodash - Create a string from array elements join with some separator
- Remove items starting from last untill given condition is false Lodash
- Get all child elements of parent element in javascript