Open In App

Lodash _.endsWith() Method

Improve
Improve
Like Article
Like
Save
Share
Report

Lodash _.endsWith() method is used to check whether the string ends with the given target string or not.

Syntax:

_.endsWith([string=''], [target], [position=string.length]);

Parameters:

  • string: This parameter holds the string that needs to be inspected.
  • target: This parameter holds the string that needs to be searched.
  • position: This parameter holds the position where search the string.

Return Value:

This method returns true if the string ends with the target string, and false otherwise.

Example 1: In this example, we are checking whether the given target string is present in the given string in the end or not by the use of the lodash _.endsWith() method.

Javascript




const _ = require('lodash');
 
let str1 = _.endsWith("GeeksforGeeks", "s");
console.log(str1);
 
let str2 = _.endsWith("GeeksforGeeks", "G");
console.log(str2);
 
let str3 = _.endsWith("GeeksforGeeks", "Geeks");
console.log(str3);


Output:

true
false
true

Example 2: In this example, we are checking whether the given target string is present in the given string in the end or not by the use of the lodash _.endsWith() method.

Javascript




const _ = require('lodash');
 
let str1 = _.endsWith("GFG", "F", 2);
console.log(str1);
 
let str2 = _.endsWith("GeeksforGeeks", "f", 5);
console.log(str2);
 
let str3 = _.endsWith("GeeksforGeeks", "for", 8);
console.log(str3);


Output:

true
false
true

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