Open In App

Lodash _.startsWith() Method

Improve
Improve
Like Article
Like
Save
Share
Report

Lodash _.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:

  • 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.

Example 1: In this example, we are checking whether the given string has the starting string the same as the given starter string or not with the help of the lodash _.startsWith() method.

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: In this example, we are checking whether the given string has the starting string the same as the given starter string or not with the help of the lodash _.startsWith() method.

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

Last Updated : 03 Nov, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads