Code Monkey home page Code Monkey logo

object-length's Introduction

object-length NPM version Build Status

Get the length of an object's properties, excluding prototype properties. Works with dontEnum bugs.

Install with npm

npm i object-length --save

Usage

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

len({a: 'a', b: 'b'});
//=> 2

Works with dontEnum bug:

len({'hasOwnProperty': 'abc', def: 'xyz'});
//=> 2

Other object utils

  • get-value: Use property paths (a.b.c) get a nested value from an object.
  • is-plain-object: Returns true if an object was created by the Object constructor.
  • for-own: Iterate over the own enumerable properties of an object, and return an object with properties that evaluate to true from the callback. Exit early by returning false. JavaScript/Node.js.
  • for-in: Iterate over the own and inherited enumerable properties of an objecte, and return an object with properties that evaluate to true from the callback. Exit early by returning false. JavaScript/Node.js
  • isobject: Returns true if the value is an object and not an array or null.
  • object.omit: Return a copy of an object without the given keys.
  • object.filter: Create a new object filtered to have only properties for which the callback returns true.
  • object.pick: Returns a filtered copy of an object with only the specified keys, like pick from lo-dash / underscore.
  • object.pluck: Like pluck from underscore / lo-dash, but returns an object composed of specified properties, with values unmodified from those of the original object.
  • object.reduce: Reduces an object to a value that is the accumulated result of running each property in the object through a callback. Executes the callback function once for each own enumerable property in the object, receiving four arguments: the initial value (or valu

Contributing

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

Running tests

Install dev dependencies.

npm i -d && npm test

Author

Jon Schlinkert

License

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


This file was generated by verb-cli on March 20, 2015.

object-length's People

Contributors

jonschlinkert avatar

Stargazers

Cat  avatar Mathieu M-Gosselin avatar Charlike Mike Reagent avatar  avatar

Watchers

 avatar Brian Woodward avatar  avatar

object-length's Issues

Is it better to use Object.keys ?

I don't sure is it will be better ?

var obj = {a: 1, b: 2, c: 3};

console.log(Object.keys(obj).length);

Object.keys will return an array with all keys of object besides of inherits. So we can use Object.keys(obj).length) to get the length of object.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.