I have a Javascript string.
var str = "an eye";
I want to split the string to get all the alphabets in an array using split() and regex. Meaning I want,
['a','n','e','y','e']
I used the following regex in match() to get the array:
var reg = /[a-z]/gi;
But, when I use the same regex in split(), it gives me an array of spaces.
["", "", " ", "", "", ""]
Please help me understand what i am missing here. I am new to both javascript and regex. TIA.
splitis "split at".n("n "instead of"n"). You should use match instead, and you can still call reverse on the array and anything else you want to do, such asstr.match(/[a-z]/gi).reverse().join('');.