Friday, September 5, 2025
HomeLanguagesJavascriptLodash _.first() Method

Lodash _.first() Method

The _.first() method is used to get the first element of the specified array.

Syntax:

_.first(array)

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

  • array: This parameter holds an array to query.

Return Value: This method returns the first element of the array.

Example 1:

Javascript




// Defining Lodash variable
const _ = require('lodash');
 
// Calling _.first() functions
console.log(_.first([5]));
console.log(_.first([2, 4, 6]));
console.log(_.first(["gfg", "GFG"]));


 

 

Output:

 

5
2
gfg

 

Example 2:

 

Javascript




// Defining Lodash variable
const _ = require('lodash');
 
// Calling _.first() functions
console.log(_.first([]));


 

 

Output:

 

undefined

 

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

 

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6634 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11861 POSTS0 COMMENTS
Shaida Kate Naidoo
6750 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6699 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS