JavaScript String concat()
Esempi
Unisci due stringhe:
let text1 = "sea";
let text2 = "food";
let result = text1.concat(text2);
Unisci due stringhe:
let text1 = "Hello";
let text2 = "world!";
let result = text1.concat(" ", text2);
Altri esempi di seguito.
Definizione e utilizzo
Il concat()
metodo unisce due o più stringhe.
Il concat()
metodo non modifica le stringhe esistenti.
Il concat()
metodo restituisce una nuova stringa.
Sintassi
string.concat(string1, string2, ..., stringX)
Parametri
Parameter | Description |
string1, string2, ... stringX | Required. The strings to be joined. |
Valore di ritorno
Tipo | Descrizione |
Una stringa | Una nuova stringa contenente le stringhe combinate. |
Altri esempi
Unisci tre stringhe:
let text1 = "Hello";
let text2 = "world!";
let text3 = "Have a nice day!";
let result = text1.concat(" ", text2, " ", text3);
Supporto browser
concat()
è una funzione ECMAScript1 (ES1).
ES1 (JavaScript 1997) è completamente supportato in tutti i browser:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |