I want a string split at every single character and put into an array. The string is:
var string = "hello";
Would you use the .split()
? If so how?
Yes, you could use:
var str = "hello";
// returns ["h", "e", "l", "l", "o"]
var arr = str.split( '' );
I was researching a similar problem.. to break on every other character. After reading up on regex, I came up with this:
data = "0102034455dola";
arr = data.match(/../g);
The result is the array: ["01","02","03","44","55","do","la"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With