_.size

Returns the number of values in the collection.

  1. // Underscore/Lodash
  2. var result = _.size({one: 1, two: 2, three: 3})
  3. console.log(result)
  4. // output: 3
  5.  
  6. // Native
  7. var result2 = Object.keys({one: 1, two: 2, three: 3}).length
  8. console.log(result2)
  9. // output: 3

Browser Support for Object.keys()

ChromeEdgeFirefoxIEOperaSafari
5.0 ✔4.0 ✔9.0 ✔12.0 ✔5.0 ✔