DEV Community


Discussion on: How to Get an Object Length

krumpet profile image
Ran Lottem

I think Object.values and Object.keys will have the same length, as they both consider only enumerable properties:

Docs for Object.values

markokolombo profile image
Marko Kolombo • Edited

true story...

const object1 = {
  a: 'somestring',
  b: 42,
  c: false,
  [Symbol('ghost')]: '👻'

console.log(Object.values(object1).length); //>3
Thread Thread
krumpet profile image
Ran Lottem

I'm getting 3 for the length of both keys and values. The arrays are ["a", "b", "c"] and ["somestring", 42, false], respectively.