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

Is there a way to keep array #117

Open
winjeysong opened this issue May 31, 2024 · 2 comments
Open

Is there a way to keep array #117

winjeysong opened this issue May 31, 2024 · 2 comments

Comments

@winjeysong
Copy link

Thanks for maintaining this library, and It helps me a lot. But is there a way to keep array like below:

import { deepKeys, getProperty } from 'dot-prop';

const o = { a: ['foo', 'bar'], b: { foo: 'bar' }, c: { d: ['foo', 'bar'] } }
deepKeys(o).forEach(key => {
  console.log(key, ': ', getProperty(o, key))
})

// logs: 
//=> a: ['foo', 'bar']
//=> b.foo: bar
//=> c.d: ['foo', 'bar']
@sindresorhus
Copy link
Owner

The point of deepKeys is to get the path to all properties. Just curious, what's your use-case? I guess it would be possible to add an option to stop at arrays.

Would you expect {a: [{c: true}, {d: false}]} to not include the paths for c and d?

@winjeysong
Copy link
Author

Yes, it might be a good idea to add an option to keep arrays, so that I can replace with new array directly, but not set array items one by one.

The point of deepKeys is to get the path to all properties. Just curious, what's your use-case? I guess it would be possible to add an option to stop at arrays.

Would you expect {a: [{c: true}, {d: false}]} to not include the paths for c and d?

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