getprop
Get a property from object
Install
npm install get-prop
Usage
var getProp = require('get-prop');
var obj = {
foo: 'bar',
qux: {
zee: {
boop: 'yo',
peep: [55,'zonk', {
__data: 'pow'
}],
},
'key.with.dots': 'hello',
'"key.with.quotes"': {
greet: 'hi'
},
$el: 'element'
},
};
getProp(obj, 'foo')
getProp(obj, 'deedee')
getProp(obj, 'deedee', "I'm default value")
getProp(obj, 'qux.zee.boop')
getProp(obj, 'qux.zee.peep.0')
getProp(obj, 'qux.zee.peep.1')
getProp(obj, 'qux.zee.peep[1]')
getProp(obj, 'qux[key.with.dots]')
getProp(obj, 'qux["key.with.quotes"].greet')
getProp(obj, 'qux.zee.peep.2.__data')
getProp(obj, 'qux.$el')
License
MIT