JS Array a['1'] doesnot gives an error

前端 未结 3 908
半阙折子戏
半阙折子戏 2021-01-28 06:05

I have declared an array a = [1,2,3,4,5]

When I write a[1] it returns 2 which is perfectly fine but when I write a[\'1\']

3条回答
  •  离开以前
    2021-01-28 06:07

    First of all, array is also object having property names as 0,1,2,....n

    Property names must be strings. This means that non-string objects cannot be used as keys in the object. Any non-string object, including a number, is typecasted into a string via the toString method. [Ref]

提交回复
热议问题