JavaScript access string chars as array

前端 未结 4 492
日久生厌
日久生厌 2020-11-30 02:34

Is it ok to do this:

var myString=\"Hello!\";
alert(myString[0]); // shows \"H\" in an alert window

Or should it be done with either charAt

4条回答
  •  北海茫月
    2020-11-30 02:51

    2018 answer: Yes it is OK to access strings like arrays.

    The syntax is clear and concise. IE6 and IE7 are long gone. I see no reason not to use it.

提交回复
热议问题