Is there a method similar to Angular's $parse service that can be used for accessing nested object properties?
Consider an object structure like this:
const obj = {
items: [
{
store: {
type: ''
}
}
]
};
Scenario: The keys 'items', 'store', and 'type' may be undefined or non-existent.
If I want to retrieve the type of the first item, my current approach is:
const firstItem = obj.items[0] || {};
const store = firstItem.store || {};
const type = store.type || 'computer';
I believe there could be a more efficient way to achieve this. Are there methods similar to Angular's $parse service or any other suggestions? Thank you!