Friday, June 12, 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
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS