I have some JS objects and they each have a grandchild property called 'products'.
E.g. ecommerce.add.products, ecommerce.remove.products, ecommerce.detail.products, ecommerce.checkout.products, ecommerce.purchase.products
I would like to access the products array regardless of what the specific object out of the above it is.
Tried 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
How can I access the nested grandchild 'products' object regardless of the parents name?