Array.size() vs Array.length

后端 未结 10 833
一个人的身影
一个人的身影 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 02:08

    we can you use .length property to set or returns number of elements in an array. return value is a number

    > set the length: let count = myArray.length;
    > return lengthof an array : myArray.length
    

    we can you .size in case we need to filter duplicate values and get the count of elements in a set.

    const set = new set([1,1,2,1]); 
     console.log(set.size) ;`
    

提交回复
热议问题