How to split string into array of words in Node.js

2 Answers

0 votes
const s = 'node.js c c++ java';

const arr = s.split(" "); 
  
arr.forEach(function(word) {
  console.log(word);
});
  
  
  
  
  
/*
run:
  
node.js
c
c++
java
  
*/

 



answered Dec 24, 2021 by avibootz
edited Feb 6, 2022 by avibootz
0 votes
const s = 'node.js c c++ java';

const [...arr] = s.split(' ');
  
console.log(arr); 
  
  
  
  
/*
run:
  
[ 'node.js', 'c', 'c++', 'java' ]
  
*/

 



answered Feb 6, 2022 by avibootz

Related questions

1 answer 137 views
2 answers 164 views
1 answer 124 views
1 answer 127 views
1 answer 149 views
...