Languages
[Edit]
EN

TypeScript - convert char array to string

0 points
Created by:
evangeline
420

In this article, we would like to show you how to convert char array to string in TypeScript.

Quick solution:

const letters: string[] = ['A', 'B', 'C'];

const result: string = letters.join('');

console.log(result); // 'ABC'

 

Practical examples

Example 1

In this example, we use join() method with an empty string ('') as a separator to convert the letters char array to the result string. 

const letters: string[] = ['A', 'B', 'C'];

const result: string = letters.join('');

console.log(result); // 'ABC'

Output:

ABC

Example 2

In this example, we use join() method with various separators.

const letters: string[] = ['A', 'B', 'C'];

const result1: string = letters.join('');
const result2: string = letters.join(' ');
const result3: string = letters.join('-');
const result4: string = letters.join('_');

console.log(result1); // 'ABC'
console.log(result2); // 'A B C'
console.log(result3); // 'A-B-C'
console.log(result4); // 'A_B_C'

Output:

ABC
A B C
A-B-C
A_B_C
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join