Skip to content

Instantly share code, notes, and snippets.

@Archakov06

Archakov06/oget.js

Created Apr 22, 2018
Embed
What would you like to do?
// Source: https://github.com/zewish/oget
'use strict';
export default (obj, path, def) => {
let res = path
.replace(/\[/g, '.')
.replace(/\]/g, '')
.replace(/^\./, '')
.split('.')
.reduce((prev, curr) => {
return prev && prev[curr]
}, obj);
return (res === undefined)
? def
: res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment