[JS]: List of indexes as path to recursive array/object
Vandesm14 (539)

I have an array which looks something like this:

[
	[
		'setA1',
		'setA2'
	],
	[
		'setB1',
		'setB2'
	]
]

(note that this is hugely over-simplified)

If I have an path to setB1 like this "1/0", how would I implement a function to recursively move down the array and return the result?
This function should also work with an object search: "key/keyA/otherkey"
Yes, I know the path is a string. For this example you can assume it has already been split by "/", making it an array of indexes

Concept of execution:

let path = '1/3/6/0/0'; // Another example
/* function turns path to obj[1][3][6][0][0] and returns result */

Thanks in advance!

You are viewing a single comment. View All
Answered by pyelias (682) [earned 5 cycles]
View Answer