Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shorter version #40

Open
dy opened this issue Oct 16, 2021 · 3 comments
Open

Shorter version #40

dy opened this issue Oct 16, 2021 · 3 comments

Comments

@dy
Copy link

dy commented Oct 16, 2021

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
Copy link
Author

dy commented Jan 30, 2022

Or even smaller (71b):

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

@danielweck
Copy link

@dy
Copy link
Author

dy commented Feb 4, 2022

that's not the point

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants