How to split string into char array in JavaScript

2 Answers

0 votes
const str = "abcdefg";
 
let charArray = str.split("");
  
console.log(charArray);


      
/*
run:
      
[
  'a', 'b', 'c',
  'd', 'e', 'f',
  'g'
]
      
*/

 



answered May 2, 2024 by avibootz
0 votes
let str = "abcdefg";
 
let charArray = [...str];
  
console.log(charArray);


      
/*
run:
      
[
  'a', 'b', 'c',
  'd', 'e', 'f',
  'g'
]

 



answered May 2, 2024 by avibootz

Related questions

1 answer 165 views
1 answer 119 views
2 answers 149 views
2 answers 202 views
4 answers 265 views
1 answer 177 views
...