Git Product home page Git Product logo

getvaluer's Introduction

getValueR

Returns the value from an array or an object.

getValueR(key, collection, result)
{string} key           The key or property name of the value (can be a string consisting of dot notation that will be used to recursivly traverse the collection).
{mixed} collection     The array or object to search.
{mixed} result         The value to return if the key does not exist.

Example

var getValueR = require("getValueR");
var object = {
	a: {
		b: {
			c: 1,
			d: [1,2,3],
			e: false
		}
	}
};
getValueR("a.b.c", object); // 1
getValueR("a.b.e", object); // false
getValueR("a.b.notExists", object, null); // null
// Arrays
var array = [["a", "b", "c"], ["A"], ["X"]];
getValueR("0.0", array); // "a"
getValueR("1.0", array); // "A"

SIMILAR PROJECTS

https://github.com/sindresorhus/dot-prop
http://davidwalsh.name/nested-objects
https://github.com/zewish/oget
https://www.npmjs.com/package/lodash.get

BENCHMARK

getvaluer (this module) x 3,251,662 ops/sec ±3.58% (78 runs sampled)
sindresorhus/dot-prop x 3,438,099 ops/sec ±2.16% (92 runs sampled)
objectifier (davidwalsh) x 1,452,507 ops/sec ±0.60% (98 runs sampled)
'getvaluer (this module)' is etalon
'sindresorhus/dot-prop' at 1.06x faster
'objectifier (davidwalsh)' at 2.24x slower

dot-prop is a little bit faster, but it does not allow to pass default value.

getvaluer's People

Contributors

unlight avatar

Watchers

 avatar James Cloos avatar  avatar

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.