6

I want to split string

"abcdefgh"

to

"ab","cd","ef","gh"

using javascript split()

"abcdefgh".split(???)

Can you please help ?

Prashant Bhate
  • 10,907
  • 7
  • 47
  • 82

1 Answers1

12

Instead of split, try match:

var text = "abcdefgh";
print(text.match(/../g));

prints:

ab,cd,ef,gh

as you can see on Ideone.

Bart Kiers
  • 166,582
  • 36
  • 299
  • 288