Skip to content

Get the length of the keys on an object. Much faster than Object.keys().

License

Notifications You must be signed in to change notification settings

jonschlinkert/keys-length

Repository files navigation

keys-length NPM version

Get the length of the keys on an object. Much faster than Object.keys()

If you need the length of an object's properties, excluding prototype properties, use object-length

Install

Install with npm

npm i keys-length --save

Usage

var len = require('keys-length');

len({a: 'b', c: 'd', e: 'f'});
//=> 3

Related projects

  • expand-object: Expand a string into a JavaScript object using a simple notation.
  • object-length: Get the length of an object's properties, excluding prototype properties. Works with dontEnum bugs.

Comparison to Object.keys()

#1: 2 keys
  'for-in loop' x 24,570,016 ops/sec ±0.65% (93 runs sampled)
  'Object.keys()' x 3,840,164 ops/sec ±0.62% (97 runs sampled)

#2: 5 keys
  'for-in loop' x 22,487,684 ops/sec ±0.83% (91 runs sampled)
  'Object.keys()' x 3,169,150 ops/sec ±0.59% (97 runs sampled)

#3: 10 keys
  'for-in loop' x 20,201,512 ops/sec ±1.06% (94 runs sampled)
  'Object.keys()' x 2,519,700 ops/sec ±0.62% (94 runs sampled)

#4: 52 keys
  'for-in loop' x 10,519,640 ops/sec ±0.61% (97 runs sampled)
  'Object.keys()' x 791,094 ops/sec ±0.63% (94 runs sampled)

Running tests

Install dev dependencies:

npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Author

Jon Schlinkert

License

Copyright (c) 2015 Jon Schlinkert Released under the MIT license.


This file was generated by verb-cli on May 12, 2015.

About

Get the length of the keys on an object. Much faster than Object.keys().

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published