Within my JS objects, there is a common grandchild property called 'products'.
For example:
ecommerce.add.products, ecommerce.remove.products, ecommerce.detail.products, ecommerce.checkout.products, ecommerce.purchase.products
I am attempting to access the products array without specifying the specific object from the list above.
One method I tried involves using regex:
var ecomProducts = ecom[('detail'|'add'|'remove'|'checkout'|'purchase')]['products'];
TypeError: ecom[(((("detail" | "add") | "remove") | "checkout") | "purchase")] is undefined
var ecomProducts = ecom[/'detail'|'add'|'remove'|'checkout'|'purchase'/]['products'];
TypeError: ecom[/'detail'|'add'|'remove'|'checkout'|'purchase'/] is undefined
Is there a way to access the nested grandchild 'products' object regardless of the parent's name?