How to split string into substrings of N characters in TypeScript

1 Answer

0 votes
const str = 'javascript c++ c typescript c# node.js';
 
const arr = str.match(/.{1,4}/g) || [];
 
console.log(arr)
 
 
   
   
   
   
/*
run:
   
["java", "scri", "pt c", "++ c", " typ", "escr", "ipt ", "c# n", "ode.", "js"] 
   
*/

 



answered Apr 15, 2022 by avibootz
...