Friday, September 20, 2024
Google search engine
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

Recent Comments