The _.tail()
function from the Underscore library in JavaScript returns all but the first element of an array. The function does not modify the original array.
Here's an example usage of the _.tail()
function:
index.tsx188 chars8 lines
In the code above, we load the Underscore library using the require()
function, and create an array of numbers. We then call the _.tail()
function on the array to obtain a new array with the first element removed. We store this new array in the tailNumbers
variable and log it to the console. We also log the original numbers
array to show that it has not been modified.
The output of the code above in the console would be:
index.tsx29 chars3 lines
Note that there is also a native Array.prototype.slice()
method in JavaScript which can achieve the same result as _.tail()
.
gistlibby LogSnag