I have object with subCategories property that contains objects where each contains subCategories as well.
const category = {
categoryId: 123,
name: "Cars",
subCategories: [
{ categoryId: 32112, name: "BMW", subCategories: [] },
{
categoryId: 12321,
name: "Audi",
subCategories: [
{
categoryId: 21312,
name: "Audi engine",
subCategories: [
{ categoryId: 1212, name: "engine-V-123", subCategories: [] },
],
},
{ categoryId: 21112, name: "Audi wheels", subCategories: [] },
],
},
{...},
{...}
],
}
I need to write a function that will return a chain of indexes. For example, if I want to get engine-V-123
engine with id 1212
, I should get:
".subCategories[1].subCategories[0].subCategories[0]"