Array.size() vs Array.length

后端 未结 10 842
一个人的身影
一个人的身影 2020-11-28 01:17

What is the difference between the two?

So I know that array.size() is a function while array.length is a property. Is there a usecase for

10条回答
  •  盖世英雄少女心
    2020-11-28 01:55

    array.length isn't necessarily the number of items in the array:

    var a = ['car1', 'car2', 'car3'];
    a[100] = 'car100';
    a.length; // 101
    

    The length of the array is one more than the highest index.

    As stated before Array.size() is not a valid method.

    More information

提交回复
热议问题