EN
JavaScript - convert char array to string
0
points
In this article, we would like to show you how to convert char array to string in JavaScript.
Quick solution:
// ONLINE-RUNNER:browser;
let letters = ['A', 'B', 'C'];
let result = letters.join('');
console.log(result); // 'ABC'
Practical example
In this example, we use join()
method with an empty string (''
) as a separator to convert the letters
char array to the result
string.
// ONLINE-RUNNER:browser;
let letters = ['A', 'B', 'C'];
let result = letters.join('');
console.log(result); // 'ABC'
join()
method with various separators example:
// ONLINE-RUNNER:browser;
let letters = ['A', 'B', 'C'];
let result1 = letters.join('');
let result2 = letters.join(' ');
let result3 = letters.join('-');
let result4 = letters.join('_');
console.log(result1); // 'ABC'
console.log(result2); // 'A B C'
console.log(result3); // 'A-B-C'
console.log(result4); // 'A_B_C'