How to convert a string to an array of characters in Node.js

2 Answers

0 votes
const str = "node.js";
 
let arr = str.split('');
     
console.log(arr);
 
 
 
 
 
/*
run:
 
[
  'n', 'o', 'd',
  'e', '.', 'j',
  's'
]
 
*/

 

 



answered Aug 26, 2022 by avibootz
0 votes
const str = "node.js";
 
let arr = [...str];
     
console.log(arr);
 
 
 
 
 
/*
run:
 
[
  'n', 'o', 'd',
  'e', '.', 'j',
  's'
]
 
*/

 



answered Aug 26, 2022 by avibootz
...