6

I want to split string

"abcdefgh"

to

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

using javascript split()

"abcdefgh".split(???)

Can you please help ?

Prashant Bhate
  • 10,568
  • 7
  • 44
  • 81

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
  • 161,100
  • 35
  • 287
  • 281