How to get nth character in a string in Javascript?

后端 未结 3 1919
情书的邮戳
情书的邮戳 2020-12-05 13:12

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

3条回答
  •  醉酒成梦
    2020-12-05 13:49

    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.

提交回复
热议问题