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 174 views
1 answer 126 views
2 answers 164 views
2 answers 217 views
4 answers 275 views
1 answer 186 views
...