From 39f2114f9797eb51994966c6bb8ff1814c9a4da8 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 12:36:08 +0100 Subject: unslug fr: move --- .../global_objects/string/trim/index.html | 96 ++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 files/fr/web/javascript/reference/global_objects/string/trim/index.html (limited to 'files/fr/web/javascript/reference/global_objects/string/trim') diff --git a/files/fr/web/javascript/reference/global_objects/string/trim/index.html b/files/fr/web/javascript/reference/global_objects/string/trim/index.html new file mode 100644 index 0000000000..963280c9e7 --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/string/trim/index.html @@ -0,0 +1,96 @@ +--- +title: String.prototype.trim() +slug: Web/JavaScript/Reference/Objets_globaux/String/trim +tags: + - ECMAScript 2015 + - JavaScript + - Méthode + - Prototype + - Reference + - String + - polyfill +translation_of: Web/JavaScript/Reference/Global_Objects/String/Trim +--- +
{{JSRef}}
+ +

La méthode trim() permet de retirer les blancs en début et fin de chaîne. Les blancs considérés sont les caractères d'espacement (espace, tabulation, espace insécable, etc.) ainsi que les caractères de fin de ligne (LF, CR, etc.).

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

Syntaxe

+ +
str.trim()
+ +

Valeur de retour

+ +

Une nouvelle chaîne de caractères dérivant de la chaîne appelante pour laquelle les blancs ont été retirés aux deux extrémités de la chaîne.

+ +

Description

+ +

La méthode trim() renvoie la chaîne sans blanc au début et à la fin. La méthode trim() n'affecte pas la valeur de la chaîne courante.

+ +

Exemples

+ +

L'exemple qui suit affiche la chaîne 'toto' :

+ +
var chaîneOriginale = '   toto  ';
+console.log(chaîneOriginale.trim()); // 'toto'
+
+// Un autre exemple de .trim() qui enlève les espaces juste d'un côté
+
+var chaîneOriginale = 'toto    ';
+console.log(chaîneOriginale.trim()); // 'toto'
+
+ +

Prothèse d'émulation (polyfill)

+ +

Si l'environnement utilisé ne possède pas cette méthode, il est possible de l'émuler avec le fragment de code suivant :

+ +
if (!String.prototype.trim) {
+  String.prototype.trim = function () {
+    return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
+  };
+}
+
+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ES5.1', '#sec-15.5.4.20', 'String.prototype.trim')}}{{Spec2('ES5.1')}}Définition initiale. Implémentée avec JavaScript 1.8.1.
{{SpecName('ES6', '#sec-string.prototype.trim', 'String.prototype.trim')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-string.prototype.trim', 'String.prototype.trim')}}{{Spec2('ESDraft')}} 
+ +

Compatibilité des navigateurs

+ + + +

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

+ +

Voir aussi

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