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/concat/index.html | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 files/fr/web/javascript/reference/global_objects/string/concat/index.html (limited to 'files/fr/web/javascript/reference/global_objects/string/concat') diff --git a/files/fr/web/javascript/reference/global_objects/string/concat/index.html b/files/fr/web/javascript/reference/global_objects/string/concat/index.html new file mode 100644 index 0000000000..184d38d6fc --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/string/concat/index.html @@ -0,0 +1,106 @@ +--- +title: String.prototype.concat() +slug: Web/JavaScript/Reference/Objets_globaux/String/concat +tags: + - JavaScript + - Méthode + - Prototype + - Reference + - String +translation_of: Web/JavaScript/Reference/Global_Objects/String/concat +--- +
{{JSRef}}
+ +

La méthode concat() combine le texte de plusieurs chaînes avec la chaîne appelante et renvoie la nouvelle chaîne ainsi formée.

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

Syntaxe

+ +
str.concat(string2[, string3, ..., stringN])
+ +

Paramètres

+ +
+
string2...stringN
+
Chaînes de caractères à concaténer ensemble.
+
+ +

Valeur de retour

+ +

Une nouvelle chaîne de caractères qui contient la concaténation des chaînes de caractères fournies.

+ +

Description

+ +

La fonction concat() renvoie une nouvelle chaîne correspondant à la concaténation des différents arguments avec la chaîne courante. La chaîne courante est celle sur laquelle a été appelée la méthode concat(). Si les valeurs passées en arguments ne sont pas des chaînes de caractères, elles sont automatiquement converties en chaînes (grâce à leur méthode toString() avant la concaténation).

+ +

Exemples

+ +

L'exemple suivant combine plusieurs chaînes afin d'en former une nouvelle.

+ +
var coucou = "Bonjour ";
+console.log(coucou.concat("Tristan,", " bonne journée."));
+
+/* Bonjour Tristan, bonne journée. */
+
+var salutation = ['Bonjour', ' ', 'Alfred', ' ', '!'];
+"".concat(...salutation); // "Bonjour Alfred !"
+
+"".concat({});   // [object Object]
+"".concat([]);   // ""
+"".concat(null); // "null"
+"".concat(true); // "true"
+"".concat(4, 5); // "45"
+
+
+ +

Performance

+ +

Il est fortement recommandé d'utiliser les {{jsxref("Opérateurs/Opérateurs_d_affectation", "opérateurs d'affectation", "", 1)}} (+, +=) plutôt que la méthode concat() pour des raisons de performance.

+ +

Spécifications

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

Compatibilité des navigateurs

+ + + +

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

+ +

Voir aussi

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