Javascript multidimensional array updating specific element

后端 未结 5 1501
一向
一向 2021-01-05 19:48

I have a string that has been converted into an 2D Array in js.

board = "...|.X.|...|"

It is used to represent a game board

each . represent

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-05 20:23

    Two remarks here:

    1. Arrays start with index 0 in every dimension.
    2. If you access a string as a 2D array, every element is a char rather than a string.

    So if you write board[0][0] = 'X'; then you get the right behavior (and that changes the first character of the string, not the second).

提交回复
热议问题