I need help creating a function in plain JavaScript that can find all paths to keys with a specific name in an object. The object may have repeated key names at different depths.
Here is an example:
const obj = {
stuff: {
A: 'text'
},
deeperStuff: {
nested: {
A: ['data']
}
}
};
const func = (object, key) => {
...
};
console.log(func(obj, 'A'));
// [['stuff', 'A'], ['deeperStuff', 'nested', 'A']]
If anyone has a solution for this problem, I would greatly appreciate it!
Thank you,
P