links: JS MOC


Description

This method lets you determine whether or not a string ends with another string. This method is case-sensitive.

Syntax

str.endsWith(searchString [, length])

Parameters:

searchString

The characters to be searched for at the end of str

length (Optional)

If provided, it is used as the length of str. Defaults to str.length

Examples

let str = 'To be, or not to be, that is the question.'
 
console.log(str.endsWith('question.')) //true
console.log(str.endsWith('to be')) // false
console.log(str.endsWith('to be', 19)) // true

tags: javascript , string

source