How to split a string and keep the whitespace in TypeScript

1 Answer

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

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

console.log(arr);

  
  
  
  
/*
run:

["typescript", " ", "javascript", " ", "php", " ", "node.js"] 
  
*/

 



answered Apr 29, 2022 by avibootz
...