I have a few arrays with like names.
ArrayTop[]
ArrayLeft[]
ArrayRight[]
ArrayWidth[]
I am trying to set the name dynamically in a f
Hash map will be a perfect tool:
var arrays = {
top: [],
left: [],
right: [],
bottom: []
};
function addToArray(name, index, value) {
arrays[name][index] = value;
}
addToArray('top', 5, 100);
I took the liberty to give more explicit names.
I suggest also two good practices:
do not use eval. Eval is not meant for this kind of dynamic evaluation. In your case, it's a performance killer
do not polute the global namespace. In browser environnement, avoid adding stuff to window (which is global).