var s = "overpopulation";
var ar = [];
ar = s.split();
alert(ar);
I want to string.split a word into array of characters.
The above code doesn’t seem to work – it returns “overpopulation” as Object..
How do i split it into array of characters, if original string doesn’t contain commas and whitespace?
You can split on an empty string:
If you just want to access a string in an array-like fashion, you can do that without
split:You can also access each character with its index using normal array syntax. Note, however, that strings are immutable, which means you can’t set the value of a character using this method, and that it isn’t supported by IE7 (if that still matters to you).