Skip to content
Related Articles

Related Articles

Improve Article

Lodash _.endsWith() Method

  • Last Updated : 07 Sep, 2020
Geek Week

Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.  

The _.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: This method accepts three parameters as mentioned above and described below:

  • string: This parameter holds the string that need to inspect.
  • target: This parameter holds the string that need to search.
  • position: This parameter holds the position where search the string.

Return Value: This method returns true if string ends with target string, false otherwise.



Example 1:

Javascript




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

Output:

true
false
true

Example 2:

Javascript




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

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 :