Why doesn't the length of the array change when I add a new property?

前端 未结 4 1681
不思量自难忘°
不思量自难忘° 2021-01-05 07:16

var arr = [\"He         


        
4条回答
  •  Happy的楠姐
    2021-01-05 08:00

    When you write:

    arr["Hello"]=...

    you are creating a new Object associated with the arr Array object, which does not affect the length of arr.

    You can achieve the same effect by writing:

    arr.Hello=...

提交回复
热议问题