The endsWith() Function is used to check, if a String ends with a particular substring.
<html>
<body>
<script>
var x = "Hello Beautiful World"
var y = x.endsWith("World")
if (y == true) {
document.write("The String ends with World")
}
else {
document.write("The String does not end with World")
}
</script>
</body>
</html>
In the above code, we have declared a String Hello Beautiful World and assigned it to a variable x.
x = "Hello Beautiful World"
-Function1.png)
And we have checked if the String, Hello Beautiful World ends with the substring World.
if (y == true) {
document.write("The String ends with World")
}
else {
document.write("The String does not end with World")
}And in this case the String, substring Hello Beautiful World ends with the substring World
And thus we get the below output.
The String ends with World