JavaScript cadena endsWith () Método : Aquí, vamos a aprender sobre el método endsWith () en JavaScript con el Ejemplo .
cadena endsWith () método Método
endsWith () es un método de cadena en JavaScript, se utiliza para comprobar si un extremos de cadena con una subcadena o no especificado.
Devuelve cierto – Si extremos de cadena con una subcadena especificada y devuelve falsa – si la cadena no termina con la subcadena especificada.
Sintaxis:
String.endsWith(substring);
Ejemplos:
Input:
str = "IncludeHelp is made for students.";
substring = "students."
//function call
str.endsWith(substring);
Output:
True
Input:
str = "IncludeHelp is made for students.";
substring = "Bye"
//function call
str.endsWith(substring);
Output:
False
Código:
<html>
<head>
<title>JavaScipt Example</title>
</head>
<body>
<script>
var str = "IncludeHelp is made for students.";
var substring = "students.";
if(str.endsWith(substring)){
document.write(str + " ends with " + substring + "<br>");
}
else{
document.write(str + " does not end with " + substring + "<br>");
}
substring = "Bye";
if(str.endsWith(substring)){
document.write(str + " ends with " + substring + "<br>");
}
else{
document.write(str + " does not end with " + substring + "<br>");
}
</script>
</body>
</html>
salida