fetch-dot
v1.2.0
Published
A pure function that allows you to retrieve a member of an object or an array utilizing dot notation
Downloads
130
Maintainers
Readme
fetchDot
A pure function that allows you to retrieve a member of an object or an array utilizing dot notation. Super useful in situations where your code may not know what the schema of an object will be, but some configuration or user might.
Usage
const obj = {
test: 'Test property.',
nestedObj: {
test: 'A nested test property.'
},
arr: [
'An array item'
]
};
fetchDot('test', obj);
// 'Test property.'
fetchDot('nestedObj.test', obj);
// 'A nested test property.'
fetchDot('arr[0]', obj);
// 'An array item'
// If a property does not exist (no matter how nested it is), the function will
// simply return undefined
fetchDot('does.not.exist', obj);
// undefined