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 103 views
1 answer 106 views
1 answer 108 views
1 answer 136 views
1 answer 144 views
...