From a55b575e8089ee6cab7c5c262a7e6db55d0e34d6 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 14:46:50 +0100 Subject: unslug es: move --- .../global_objects/string/endswith/index.html | 88 ++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 files/es/web/javascript/reference/global_objects/string/endswith/index.html (limited to 'files/es/web/javascript/reference/global_objects/string/endswith') diff --git a/files/es/web/javascript/reference/global_objects/string/endswith/index.html b/files/es/web/javascript/reference/global_objects/string/endswith/index.html new file mode 100644 index 0000000000..cbeac4f481 --- /dev/null +++ b/files/es/web/javascript/reference/global_objects/string/endswith/index.html @@ -0,0 +1,88 @@ +--- +title: String.prototype.endsWith() +slug: Web/JavaScript/Referencia/Objetos_globales/String/endsWith +tags: + - JavaScript + - Prototipo + - Referencia + - String + - metodo +translation_of: Web/JavaScript/Reference/Global_Objects/String/endsWith +--- +
{{JSRef}}
+ +

El método endsWith() determina si una cadena de texto termina con los caracteres de una cadena indicada, devolviendo true o false según corresponda.

+ +
{{EmbedInteractiveExample("pages/js/string-endswith.html")}}
+ +

Sintaxis

+ +
str.endsWith(searchString[, position])
+ +

Parámetros

+ +
+
searchString
+
Los caracteres a buscar hasta el final de la cadena str.
+
length {{optional_inline}}
+
Si se indica, se utiliza como el tamaño de str. Por defecto se usa str.length.
+
+ +

Valor devuelto

+ +

true si los caracteres proporcionados se encuentran al final de la cadena de texto; en caso contrario, false.

+ +

Descripción

+ +

Este método determina si una cadena de texto termina en otra cadena o no. Este método distingue entre mayúsculas y minúsculas.

+ +

Polyfill

+ +

Este método ha sido añadido a la especificación ECMAScript 6 y puede no estar disponible en todas las implementaciones de JavaScript. Sin embargo, puedes implementar el polyfill String.prototype.endsWith() con el siguiente fragmento de código:

+ +
if (!String.prototype.endsWith) {
+	String.prototype.endsWith = function(search, this_len) {
+		if (this_len === undefined || this_len > this.length) {
+			this_len = this.length;
+		}
+		return this.substring(this_len - search.length, this_len) === search;
+	};
+}
+
+ +

Ejemplos

+ +

Usando endsWith()

+ +
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
+
+ +

Especificaciones

+ + + + + + + + + + +
Specification
{{SpecName('ESDraft', '#sec-string.prototype.endswith', 'String.prototype.endsWith')}}
+ +

Compatibilidad en navegadores

+ +

{{Compat("javascript.builtins.String.endsWith")}}

+ +

Ver también

+ + -- cgit v1.2.3-54-g00ecf