Skip to content
Related Articles

Related Articles

Improve Article

Lodash _.startsWith() Method

  • Last Updated : 03 Sep, 2020
Geek Week

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('geeksforgeeks', 'g')); 
console.log(_.startsWith('geeksforgeeks', 'f'));

Output:

true
false

Example 2:  

Javascript




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

Output:

true
false
true

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it’s lowest price ever!

My Personal Notes arrow_drop_up
Recommended Articles
Page :