Saturday, October 25, 2025
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
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS