I am working with nested object arrays within an array and looking to determine the path of a specific key.
For instance:
const dataList = [
[
[{id: 100,name: 'Test1'}, {id: 120,'Test12'}],
[{id: 101,name: 'Test1'}, {id: 121,'Test12'}],
[{id: 102,name: 'Test1'}, {id: 122,'Test12'}],
[
[{id: 103,name: 'Test1'}, {id: 123,'Test12'}],
[{id: 104,name: 'Test1'}, {id: 124,'Test12'}],
[{id: 105,name: 'Test1'}, {id: 125,'Test12'}],
]
],
[{id: 2,name: 'Test2'}, {id: 13,'Test13'}],
[{id: 3,name: 'Test3'}, {id: 14,'Test14'}],
[{id: 4,name: 'Test4'}, {id: 15,'Test15'}],
[{id: 5,name: 'Test5'}, {id: 16,'Test16'}],
[{id: 6,name: 'Test6'}, {id: 17,'Test17'}],
[{id: 7,name: 'Test7'}, {id: 18,'Test18'}],
[{id: 8,name: 'Test8'}, {id: 19,'Test19'}],
];
function findIndexPath(list, targetId) {
//....
}
findIndexPath(dataList, 104); //result should be [0,3,1,0]
findIndexPath(dataList, 16); //result should be [4,1]
The arrays may have multiple levels of nesting.