Thursday, September 4, 2025
HomeLanguagesJavascriptLodash _.tail() Function

Lodash _.tail() Function

The _.tail() method is used to create a new array that doesn’t contain the first element of the original array.

Syntax:

_.tail( array )

Parameters: This method accepts single parameter as mentioned above and described below:

  • array: This parameter holds the query array.

Return Value: This method returns the slice of an array.

Example 1:




const _ = require('lodash');
  
let x = [1, 2, 3, 4, 5, 6, 7]
  
let newArray = _.tail(x);
  
console.log(newArray);


Here, const _ = require('lodash') is used to import the lodash library into the file.

Output:

[ 2, 3, 4, 5, 6, 7 ]

Example 2:




const _ = require('lodash');
  
let x = [
    {'name': 'lodash'}, 
    {'name': 'npm'}, 
    {'name': 'nodejs'}
]
  
let newArray = _.tail(x);
  
console.log(newArray);


Output:

[ { name: 'npm' }, { name: 'nodejs' } ]

Example:




const _ = require('lodash');
  
let x = [1, 2, 'a', {'name': 'hello'}]
  
let newArray = _.tail(x);
  
console.log(newArray);


Output:

[ 2, 'a', { name: 'hello' } ]

Note: This will not work in normal JavaScript because it requires the library lodash to be installed.

Reference: https://lodash.com/docs/4.17.15#tail

RELATED ARTICLES

Most Popular

Dominic
32263 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6627 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11858 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6696 POSTS0 COMMENTS
Umr Jansen
6716 POSTS0 COMMENTS