To use the initial function from the lodash library in typescript, you first need to install lodash:
19 chars2 lines
Then, you can import the initial function from lodash and use it to get all but the last element of an array:
index.ts147 chars7 lines
The initial
function takes an array as its first argument and returns a new array with all but the last element. Note that initial
does not modify the original array, but returns a new one. Also, if the original array is empty or has only one element, initial
will return an empty array.
gistlibby LogSnag