Split string by # of chars We can use the .match regular expression function to split a string by n characters.

PHOTO EMBED

Wed Feb 22 2023 09:02:35 GMT+0000 (Coordinated Universal Time)

Saved by @EMR4HKLMN

const str = "asdfghjklmnopq";
const splitPairs = str.match(/.{1,2}/g);

console.log(splitPairs); // ['as', 'df', 'gh', 'jk', 'lm', 'no', 'pq']
content_copyCOPY

https://dev.to/ironcladdev/15-killer-js-techniques-youve-probably-never-heard-of-1lgp