get function can not retrieve the value from an json object which have complex key name.
get function can not get value from below json object, but lodash can! 😂
{"/api-v1.2": "some-value"}
No need for get in this instance.
const routeCfg = configs[routeName] ?? {}
Lodash uses a complicated and much less performant regex approach, which apparently works in your case because the period . is part of a number 1.5.
Due to its simplified implementation, I would avoid using Radash get in cases where the key may contain periods.
P.S. Check out Radashi, an actively maintained fork of Radash with many improvements and new functions
Why I want to use either radash.get() or loads.get() method is because the configs object can be undefined, I don’t want it to throw an error.
const routeCfg = configs?.[routeName] ?? {}
const routeCfg = configs?.[routeName] ?? {}
How about the key here is a multiple level key of nested objects?
Don't know what you mean. Give an example with input data and expected result. Use triple backticks to quote the code, so I can copy-paste it.
Don't know what you mean. Give an example with input data and expected result. Use triple backticks to quote the code, so I can copy-paste it.
Think of the scenario where you want to use get method to retrieve a json value.
Anw, I just want to report a bug here, not asking for workaround 🤣
It's not really a bug, just a limitation. Something is only a bug if it's a documented behavior that isn't working as expected. You're actually making a feature request.
Semantics aside, if we can't understand your use case, we can't solve your problem. That's where a minimal example helps much more than you'd think.
It's quite possible your expectation is unrealistic and you're using the wrong tool for the job. We're all guilty of such things, now and again.
Ok, you can take this as a feature request, but I believe many people are just like me, we don’t quite understand its subtle limitations before using a “replacement“ function which other libraries can work.
And then why I would like to use get methods?
According to what you said, there are always ways to get the value in the json object without using third-party libraries and functions, just using a lot of conditional statements and non-null judgments to ensure that no errors are thrown.