Get, set, or delete a property from a nested object using a dot path
by sindresorhusJavaScript
When accessing a object using with an empty array, it currently returns the fallback value. This came to me as a surprise, isn't an empty string a zero nested path to the root object? https://github.com/sindresorhus/dot-prop/blob/8e81843270e42051ea8fda6035de1d638856fad5/index.js#L274-L277 Changing this would probably be a breaking change, but I think it would be more consistent.
I understand that this is an edge-case and I can imagine that you would not want to add support for this, however I am sharing since we needed this code for our use-case. We can use this from our fork, but if this is helpful for others then you're free to use it here. This adds support for a new syntax for accessing specific array properties for arrays of objects, by filtering on a specific item property e.g. to access the first array item where . only JSON primitive types (string, number, boolean, null) setProperty only updates existing items, doesn't create new ones
Repository: sindresorhus/dot-prop. Description: Get, set, or delete a property from a nested object using a dot path Stars: 868, Forks: 122. Primary language: JavaScript. License: MIT. Open PRs: 0, open issues: 4. Last activity: 9mo ago. Top contributors: sindresorhus, Richienb, stevemao, AuthorProxy, bendrucker, LinusU, SamVerschueren, floatdrop, kphrx, stroncium and others.