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

前端 未结 3 907
半阙折子戏
半阙折子戏 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:13

    All property names are strings.

    If you pass a number, it gets converted to a string before being used to look up the property value.

    console.log(1 == '1');

提交回复
热议问题