Array.length vs Array.prototype.length

前端 未结 4 1911
Happy的楠姐
Happy的楠姐 2020-12-19 15:20

I found that both the Array Object and Array.prototype have the length property. I am confused on using the Array.length

4条回答
  •  囚心锁ツ
    2020-12-19 15:50

    Array.length is how many arguments the function Array() takes and Array.prototype.length is an instance method that gives you the length of your array. When you check ['foo'].length you're actually checking Array.prototype.length with the this argument being your array ['foo']

    var myArray = ['a','b','c']
    console.log(myArray.length); //logs 3

提交回复
热议问题