Lodash _.endsWith() Method
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( "w3wiki" , "s" ); console.log(str1); let str2 = _.endsWith( "w3wiki" , "G" ); console.log(str2); let str3 = _.endsWith( "w3wiki" , "Beginner" ); 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( "w3wiki" , "f" , 5); console.log(str2); let str3 = _.endsWith( "w3wiki" , "for" , 8); console.log(str3); |
Output:
true
false
true
Contact Us