| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith | [Back] [Original] |
Get to know MDN better
Esta pgina ha sido traducida del ingls por la comunidad. Aprende ms y nete a la comunidad de MDN Web Docs.
Esta caracterstica est consolidada y funciona en muchos dispositivos y versiones de navegador. Est disponible en todos los navegadores desde septiembre de 2015.
El mtodo endsWith() determina si una cadena de texto termina con los caracteres de una cadena indicada, devolviendo true o false segn corresponda.
const str1 = "Cats are the best!";
console.log(str1.endsWith("best!"));
// Expected output: true
console.log(str1.endsWith("best", 17));
// Expected output: true
const str2 = "Is this a question?";
console.log(str2.endsWith("question"));
// Expected output: false
str.endsWith(searchString[, position])
searchStringLos caracteres a buscar hasta el final de la cadena str.
length OpcionalSi se indica, se utiliza como el tamao de str. Por defecto se usa str.length.
true si los caracteres proporcionados se encuentran al final de la cadena de texto; en caso contrario, false.
Este mtodo determina si una cadena de texto termina en otra cadena o no. Este mtodo distingue entre maysculas y minsculas.
Este mtodo ha sido aadido a la especificacin 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 cdigo:
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;
};
}
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
| Especificacin |
|---|
| ECMAScript 2027 LanguageSpecification # sec-string.prototype.endswith |
String.prototype.startsWith()String.prototype.includes()String.prototype.indexOf()String.prototype.lastIndexOf()Esta pgina se modific por ltima vez el 11 feb 2025 por colaboradores de MDN.
StringString.prototype.anchor()at()String.prototype.big()String.prototype.blink()String.prototype.bold()String.prototype.charAt()String.prototype.charCodeAt()String.prototype.codePointAt()String.prototype.concat()String.prototype.endsWith()String.prototype.fixed()String.prototype.fontcolor()String.prototype.fontsize()String.prototype.includes()String.prototype.indexOf()isWellFormed()String.prototype.italics()String.prototype.lastIndexOf()String.prototype.link()String.prototype.localeCompare()String.prototype.match()String.prototype.matchAll()String.prototype.normalize()padEnd()String.prototype.padStart()String.prototype.repeat()String.prototype.replace()String.prototype.replaceAll()String.prototype.search()String.prototype.slice()String.prototype.small()String.prototype.split()String.prototype.startsWith()String.prototype.strike()String.prototype.sub()String.prototype.substr()String.prototype.substring()String.prototype.sup()String.prototype.toLocaleLowerCase()String.prototype.toLocaleUpperCase()String.prototype.toLowerCase()String.prototype.toString()String.prototype.toUpperCase()toWellFormed()String.prototype.trim()String.prototype.trimEnd()trimStart()String.prototype.valueOf()[Symbol.iterator]()Object/FunctionPartes de este contenido son 19982026 de colaboradores individuales de mozilla.org. Contenido disponible bajo una licencia Creative Commons.
| Web Proxy Viewer | New URL | Original Page |