Could someone help describe the two types of array storage in Javascript?

前端 未结 2 667
抹茶落季
抹茶落季 2021-02-05 18:50

I\'m reading this article about V8 on HTML5Rocks. The article is old but I understand almost none of it and it bothers me. I\'m taking this 1 step at a time but could someone

2条回答
  •  一向
    一向 (楼主)
    2021-02-05 19:01

    sir i can be wrong but according to your question what i have observed is explained

    when we initialise an array it internally gets key as 0,1,2....etc as i pushed element with value its into array but array does not consider it

    ex :
    
    var arr = new Array()
    
    arr[0] = 1
    arr[1] = 2
    arr[2] = "myname";
    arr['myname'] = nick;
    

    but when i do arr.length i get 3 so it does not consider the key apart from numeric but if i write arr[3] = {myname:'nick'} then it consider it as elements.

    internally i think to keep the linear array different it looks for '{}'

提交回复
热议问题