Method concat()
menggabungkan dua teks atau lebih menjadi sebuah string baru.
Syntax
str.concat(string2, string3[, ..., stringN])
Parameter
string2...stringN
- String untuk menggabungkan string.
Deskripsi
Fungsi concat()
menggabungkan teks dari satu atau lebih string dan mengembalikanya menjadi sebuah string. Perubahan pada salah satu teks tidak mempengaruhi string lainnya.
Contoh
Penggunaan concat()
Untuk menggabungkan string menjadi sebuah string baru seperti pada contoh dibawah.
var halo = 'Halo, ';
console.log(halo.concat('Didik', ' semoga hari ini menyenangkan.'));
/* Halo, Didik semoga hari ini menyenangkan. */
Performa
Sangat disarankan untuk menggunakan assignment operators (+
, +=
) pada method concat()
. lihat test performa berikut ini.
Spesifikasi
Spesifikasi | Status | Comment |
---|---|---|
ECMAScript 3rd Edition (ECMA-262) | Standard | Initial definition. Implemented in JavaScript 1.2. |
ECMAScript 5.1 (ECMA-262) The definition of 'String.prototype.concat' in that specification. |
Standard | |
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'String.prototype.concat' in that specification. |
Standard | |
ECMAScript Latest Draft (ECMA-262) The definition of 'String.prototype.concat' in that specification. |
Draft |
Kompabilitas browser
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Fitur | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Dukungan dasar | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Fitur | Android | Chrome untuk Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Dukungan dasar | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |