I\'ve a string (let\'s say \"Hello World\") and I want to save the first characters of it in different variables (ex. character1 = \"H\", character2 = \"e\"...).
How
Not sure if this is cross-browser safe, but you can use array-like indexing:
"Hello"[0] -> "H"
The syntax is exactly the same in Python.
Use the charAt method. As far as client or server, it depends on the context. But you should not trust client input.
given:
var string = "HAI";
/* and */
var index = 1; // number ∈ [0..string.length), rounded down to integer
string.charAt(index)
returns "A"
(preferred)string[index]
returns "A"
(non-standard)string.substring(index, index+1)
returns "A"
(over-complex solution but works)string.substr(index, 1)
returns "A"
(non-standard approach to above)