I am struggling with managing 5 arrays in JavaScript based on a variable called "x". I'm having difficulty understanding how to properly use and update these variables in my code. Here is an overview of what I'm trying to achieve...
//Arrays to hold IDs of nodes
nodeOne = [];
nodeTwo = [];
nodeThree = [];
nodeFour = [];
nodeFive = [];
//Mapping buttons to node arrays
var nodesButtonToNode = {pn_btn_1:"nodeOne", pn_btn_2:"nodeTwo", pn_btn_3:"nodeThree", pn_btn_4:"nodeFour", pn_btn_5:"nodeFive"};
x = "pn_btn_1";
nodesButtonToNode.x.push("I am supposed to go into nodeOne")
In essence, the value of "x" determines which array should be filled according to the key in nodesButtonToNode. For instance, if x = “pn_btn_1”, then data should be added to the nodeOne array. However, I keep encountering undefined errors and can't pinpoint where I'm making a mistake.
Any advice or insights would be greatly appreciated. Thank you!