I want to split a string every 4 characters and push them into an array. I have been trying to loop through using .substring but my loop stops at the first 4 characters.
So want to turn this string…
let list = "abcdefghijklmnop"
into this array…
[ "abcd", "efgh", "ijkl", "mnop"]
2
Answers
You can achieve this by using a loop to iterate over the string and extracting substrings of 4 characters at a time.
Here’s code to achieve your result:
Output:
You could take a regular expression which searches for four characters.