How can I split a string into segments of n characters?

As the title says, I’ve got a string and I want to split into segments of n characters.

For example:

var str="abcdefghijkl";

after some magic with n=3, it will become

var arr = ['abc','def','ghi','jkl'];

Is there a way to do this?

16 Answers
16

Leave a Comment