Last active
December 27, 2016 21:50
-
-
Save davelnewton/9f23201c9a227c2b18ae4732ad424737 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var foo = [] | |
for (var i=0; i<=1000000; i++) { | |
foo[i] = 'bar' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Updated: Assigns through loop variables named v0 through v100000 | |
all assigned the value 'bar'. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let cde = "" | |
for (var i=0; i<=100000; i++) { | |
cde = "var v" + i + " = 'bar'" | |
eval(cde) | |
} | |
alert(v11559) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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