I am faced with a situation where I have a collection of interdependent elements, each identified by a unique code (enumeration). My goal is to retrieve the list of elements that depend on a specific element, and then be able to reference them using myElements[anElementCode]
:
enum Code {
A = 'A',
B = 'B',
C = 'C',
D = 'D',
}
function main() {
let myElements = [
{ Code.C: [Code.A, Code.B] },
{ Code.D: [Code.B] }
]
console.log(`The Elements that depend on C are: ${myElements[Code.C]}`);
}
I want to be able to access the list [Code.A, Code.B]
using myElements[Code.C]
Although this code doesn't currently work as intended, I am curious if there is a workaround to achieve the desired functionality?