How to convert a string to an array of characters in TypeScript

2 Answers

0 votes
const str = "typescript";
 
let arr : string[] = str.split('');
     
console.log(arr);
 
 
 
 
/*
run:
 
["t", "y", "p", "e", "s", "c", "r", "i", "p", "t"] 
 
*/

 



answered Aug 26, 2022 by avibootz
0 votes
const str = "typescript";
 
let arr : string[] = [...str];
     
console.log(arr);
 
 
 
 
/*
run:
 
["t", "y", "p", "e", "s", "c", "r", "i", "p", "t"] 
 
*/

 



answered Aug 26, 2022 by avibootz
...