Skip to content

Instantly share code, notes, and snippets.

@davelnewton
Last active December 27, 2016 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davelnewton/9f23201c9a227c2b18ae4732ad424737 to your computer and use it in GitHub Desktop.
Save davelnewton/9f23201c9a227c2b18ae4732ad424737 to your computer and use it in GitHub Desktop.
Depending on your goals this is a quick and efficient way to store a bunch of 'variables'
as the same value. The obvious down-fall being that you have to reference them by their
number which you may not know right off the bat. It's pretty fun though.
var foo = []
for (var i=0; i<=1000000; i++) {
foo[i] = 'bar'
}
Updated: Assigns through loop variables named v0 through v100000
all assigned the value 'bar'.
let cde = ""
for (var i=0; i<=100000; i++) {
cde = "var v" + i + " = 'bar'"
eval(cde)
}
alert(v11559)
I'm asking how this array-based solution assists the OP in any way. Let's say you actually
had a reasonable way to get the varying data into array fields. Now you have position-dependent
variable access, which is almost always a smell in JS. Let's say you switch it to a more
reasonable solution using objects: you're not really reducing any typing or cognitive
overhead. If you can show me how this directly relates to the question being asked with
a code sample mirroring the OP's I'm happy to reconsider.
You can be a hater all you want my solution is more fun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment