developit/dlv

Shorter version

dy opened this issue · 3 comments

dy commented

Smallest possible implementation: only 120 bytes.

There's possibly smaller version:

export dlv = (obj, key) => (key.split ? key.split('.') : key).reduce((a,b)=>b?a?.[b]:a,obj)
dy commented

Or even smaller (71b):

export default (obj, key) => (key.split?.('.') || key).reduce((a,b)=>a?.[b],obj)
dy commented

that's not the point

export default (obj, key) => (key.map?key:key.split('.')).reduce((a,b)=>a?a[b]:a,obj)