How to split a string by multiple spaces in Node.js

1 Answer

0 votes
const str = 'typescript javascript node.js python';

const arr = str.trim().split(/\s+/);

console.log(arr); 


  
  
  
  
/*
run:
  
[ 'typescript', 'javascript', 'node.js', 'python' ]
  
*/

 



answered Apr 29, 2022 by avibootz

Related questions

1 answer 116 views
1 answer 117 views
1 answer 115 views
1 answer 149 views
1 answer 157 views
...