0

How is the length of an object calculated?

console.log({0:"a",1:"b"}.length)//returns undefined but object has the length property


Object.hasOwnProperty("length") // true

But how can hasOwnProperty() work?Object dont have this method ,the method is in its prototype

Maizere Pathak.Nepal
  • 2,235
  • 3
  • 21
  • 38

1 Answers1

1

You can use

Object.keys({0:"a",1:"b"}).length;    
Lennart
  • 938
  • 1
  • 9
  • 26