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/includes/index.html | 108 +++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 files/es/web/javascript/reference/global_objects/string/includes/index.html (limited to 'files/es/web/javascript/reference/global_objects/string/includes') diff --git a/files/es/web/javascript/reference/global_objects/string/includes/index.html b/files/es/web/javascript/reference/global_objects/string/includes/index.html new file mode 100644 index 0000000000..094a3fd648 --- /dev/null +++ b/files/es/web/javascript/reference/global_objects/string/includes/index.html @@ -0,0 +1,108 @@ +--- +title: String.prototype.includes() +slug: Web/JavaScript/Referencia/Objetos_globales/String/includes +tags: + - Cadena de texto + - JavaScript + - Prototipo + - Referencia + - String + - metodo +translation_of: Web/JavaScript/Reference/Global_Objects/String/includes +--- +
{{JSRef}}
+ +

El método includes() determina si una cadena de texto puede ser encontrada dentro de otra cadena de texto, devolviendo true o false según corresponda.

+ +
{{EmbedInteractiveExample("pages/js/string-includes.html", "shorter")}}
+ +

Sintaxis

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

Parametros

+ +
+
searchString
+
Una cadena a buscar en el texto str.
+
position {{optional_inline}}
+
La posición dentro de la cadena en la cual empieza la búsqueda de searchString (Por defecto este valor es 0).
+
+ +

Valor devuelto

+ +

true si la cadena de texto contiene la cadena buscada; en caso contrario, false.

+ +

Descripción

+ +

Este método permite determinar si una cadena de texto se encuentra incluida dentro de la otra.

+ +

Sensibilidad a Mayúsculas/Minúsculas

+ +

El método includes() es "case sensitive" (tiene en cuenta mayúsculas y minúsculas). Por ejemplo, la siguiente expresión devolverá false:

+ +
'Ballena azul'.includes('ballena'); // devuelve false
+
+ +

Polyfill

+ +

Este método ha sido agregado a la especificación ECMAScript 2015 y puede no estar  disponible en toda las implementaciones de JavaScript.

+ +

Sin embargo, puedes usar este método como polyfill:

+ +
if (!String.prototype.includes) {
+  String.prototype.includes = function(search, start) {
+    'use strict';
+
+    if (search instanceof RegExp) {
+      throw TypeError('first argument must not be a RegExp');
+    }
+    if (start === undefined) { start = 0; }
+    return this.indexOf(search, start) !== -1;
+  };
+}
+
+ +

Ejemplos

+ +

Usando includes()

+ +
const str = 'To be, or not to be, that is the question.'
+
+console.log(str.includes('To be'))        // true
+console.log(str.includes('question'))     // true
+console.log(str.includes('nonexistent'))  // false
+console.log(str.includes('To be', 1))     // false
+console.log(str.includes('TO BE'))        // false
+console.log(str.includes(''))             // true
+
+ +

Especificaciones

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

Compatibilidad en navegadores

+ +

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

+ +

Ver también

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