How do I split a string into an array of characters?

You can split on an empty string: var chars = "overpopulation". Split(''); If you just want to access a string in an array-like fashion, you can do that without split: var s = "overpopulation"; for (var I = 0; I Log(s. CharAt(i)); }.

It's as simple as: s. Split(""); The delimiter is an empty string, hence it will break up between each single character.

A string in Javascript is already a character array. You can simply access any character in the array as you would any other array. Var s = "overpopulation"; alert(s0) // alerts o.

UPDATE As is pointed out in the comments below, the above method for accessing a character in a string is part of ECMAScript 5 which certain browsers may not conform to. An alternative method you can use is charAt(index). Var s = "overpopulation"; alert(s.

CharAt(0)) // alerts o.

2 This does not work in all browsers though (not in some versions of IE: developer.mozilla. Org/en/JavaScript/Reference/Global_Objects/…. – Felix Kling Jun 26 at 14:55 Thanks Felix.

I've updated my answer to include charAt as defined pre ECMAScript 5. – Jamie Dixon Jun 26 at 15:01.

The split() method in javascript accepts two parameters: a separator and a limit. The separator specifies the character to use for splitting the string. If you don't specify a separator, the entire string is returned, non-separated.

But, if you specify the empty string as a separator, the string is split between each character. Therefore: s. Split('') will have the effect you seek.

More information here.

You can use the regular expression /(?! $)/: "overpopulation". Split(/(?!

$)/) The negative look-ahead assertion (?! $) will match right in front of every character.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions