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,293
  • 3
  • 24
  • 41

1 Answers1

1

You can use

Object.keys({0:"a",1:"b"}).length;    
Lennart
  • 988
  • 1
  • 10
  • 27