ES6 - String.prototype.endsWith ()

Cette fonction détermine si une chaîne se termine par les caractères d'une chaîne spécifiée et renvoie vrai ou faux.

Syntaxe

La syntaxe mentionnée ci-dessous est pour String.prototype.endsWith(), où, searchString correspond aux caractères à rechercher à la fin de cette chaîne. lengthest un paramètre facultatif. Il représente la longueur de la chaîne.

str.endsWith(searchString[, length])

Exemple

<script>
   let company = 'TutorialsPoint'
   console.log(company.endsWith('Point'));
   console.log(company.endsWith('Tutor',5))//5 is length of string
</script>

La sortie du code ci-dessus sera comme mentionné ci-dessous -

true
true