Thursday, January 22, 2026
HomeLanguagesJavascriptLodash _.startsWith() Method

Lodash _.startsWith() Method

The _.startsWith() method is used to find if the string starts with the given target string or not. It returns true if the string starts with the given target string. Otherwise, it returns false.

Syntax:

_.startsWith( [string = ''], [target], [position = 0] )

Parameters: This method accepts three parameters as mentioned above and described below:

  • string: This parameter holds the string to inspect.
  • target: This parameter holds the string to search for.
  • position: This parameter holds the position to search from.

Return Value: This method returns the true if the string starts with a target string, else false.

Below examples illustrate the Lodash _.startsWith() method in JavaScript:

Example 1:

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
       
// Use of _.startsWith() method 
console.log(_.startsWith('neveropen', 'g')); 
console.log(_.startsWith('neveropen', 'f'));


Output:

true
false

Example 2:  

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
       
// Use of _.startsWith() method 
console.log(_.startsWith('neveropen', 'e', 1 )); 
console.log(_.startsWith('neveropen', 'e', 4 )); 
console.log(_.startsWith('neveropen', 'e', 10));


Output:

true
false
true
RELATED ARTICLES

Most Popular

Dominic
32475 POSTS0 COMMENTS
Milvus
119 POSTS0 COMMENTS
Nango Kala
6847 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12064 POSTS0 COMMENTS
Shaida Kate Naidoo
6986 POSTS0 COMMENTS
Ted Musemwa
7220 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6912 POSTS0 COMMENTS