Home javascript How do I "dereference" a variable's content for use as a variable name?

# javascript How do I "dereference" a variable's content for use as a variable name?

user1209
1#
user1209 Published in March 22, 2018, 9:42 pm
 I want to reduce the I/O overhead of fetching information from the server using XMLHttpRequest() or ActiveXObject(), as appropriate, by making a general-purpose function for doing the fetch which then stores the fetched data using sessionStorage.. The trouble is, I don't know in advance what the variable names all are, and I intentionally don't want to know. I was thinking that if there is some way to "dereference" a variable, like we can easily do in BASH, for example, this would be trivial. For example, if the fetched data was in newData, and the name of the file it was fetched from is in dataFile, and if the dereference syntax was, say $(), then one could write code like this to store and fetch the data: //Store the data: sessionStorage.$(dataFile) = newData; //Fetch the data: var storedData = sessionStorage.\$(dataFile);  Get it? ... OK, now, how do I ACTUALLY do this?! ...The only other way around this I can see is VERY clumsy - make arrays, one with name, another with values - there MUST be an easier way! TIA.
 You need to login account before you can post.
Processed in 0.300055 second(s) , Gzip On .