A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/String/includes below:

String.prototype.includes() - JavaScript | MDN

String.prototype.includes()

Baseline Widely available

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.

Pruébalo
const sentence = "The quick brown fox jumps over the lazy dog.";

const word = "fox";

console.log(
  `The word "${word}" ${
    sentence.includes(word) ? "is" : "is not"
  } in the sentence`,
);
// Expected output: "The word "fox" is in the sentence"
Sintaxis
str.includes(searchString[, position])
Parametros
searchString

Una cadena a buscar en el texto str.

position Opcional

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 Compatibilidad con navegadores Ver también

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4