Chrome Extension

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]
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

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.

Search Index Data (The code snippet can also be found with below search text)

_.initial Lodash
Was this helpful?
0 Comments
Join Devsheet Ask a Question