--- title: String.prototype.trimEnd() slug: Web/JavaScript/Reference/Global_Objects/String/trimEnd tags: - JavaScript - Méthode - Prototype - Reference - String translation_of: Web/JavaScript/Reference/Global_Objects/String/trimEnd original_slug: Web/JavaScript/Reference/Objets_globaux/String/trimEnd ---
La méthode trimEnd()
permet de retirer les blancs situés à la fin d'une chaîne de caractères. trimRight()
est un synonyme pour cette méthode.
str.trimEnd(); str.trimRight();
Une nouvelle chaîne de caractères basée sur la chaîne appelante et dont les blancs en fin de chaîne ont été supprimés.
La méthode trimEnd()
renvoie la chaîne de caractères sans les blancs présents à partir de la droite de la chaîne. trimEnd()
ne modifie pas la chaîne elle-même.
Pour des raisons de cohérence avec les méthodes existantes comme {{jsxref("String.prototype.padEnd")}}, le nom standard de cette méthode est trimEnd
. Toutefois, à des fins de compatibilité web, trimRight
est un synonyme de trimEnd
. Pour certains moteurs JavaScript, on pourra donc avoir :
String.prototype.trimRight.name === "trimEnd";
L'exemple qui suit illustre comment afficher la chaîne " toto":
var str = " toto "; console.log(str.length); // 9 str = str.trimEnd(); console.log(str.length); // 7 console.log(str); // " toto"
Spécification | État | Commentaires |
---|---|---|
Proposition pour String.prototype.{trimStart,trimEnd} |
Brouillon de niveau 4 | Attendu pour ES2019 |
{{Compat("javascript.builtins.String.trimEnd")}}