-
-
Notifications
You must be signed in to change notification settings - Fork 93
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
Support array index access #71
Comments
For now I've had to update a few points in the code to set a default value manually, e.g. something like this: // previously
const myValue = dotProp.get(data, 'foo.bar.3', defaultValue)
// after 4->6
let myValue = dotProp.get(data, 'foo.bar.3')
if (myValue === undefined) {
myValue = defaultValue
} |
It's not even a breaking change as the behavior was never documented or officially supported. It only worked as a side-effect of the fact that arrays in JS are just objects. That being said, the behavior you describe does make sense. However, this is a new feature and will need lots of tests and docs. |
The expected behaviour here seems to have been fixed by #75. |
As long as it's not documented and tested, it could break in any patch release. |
I ran into this issue when upgrading from 4->6, which of course is a breaking change, but I think the new behavior is inconsistent. 🙇
Consider some objects that have arrays, like:
I want to access properties on the array's objects, and provide a default value if it doesn't exist.
However, in 4->6 the behavior changed when accessing an array index that doesn't exist:
I think that this behavior is ... inconsistent, probably?
If accessing a deeper property in an array element triggers a default value fallback, shouldn't accessing an array element trigger a fallback if that index doesn't exist?
The text was updated successfully, but these errors were encountered: