As the title suggests, I wish to use the name of an array as a string. I have tried some things but i'm not sure if it is even related to the problem i'm having.
-
Hi, please show some of what you tried so that everyone will be able to help yout3__rry– t3__rry2018-09-12 12:19:22 +00:00Commented Sep 12, 2018 at 12:19
-
what do you mean by 'name of an array'?Chris Li– Chris Li2018-09-12 12:20:32 +00:00Commented Sep 12, 2018 at 12:20
-
When I say name of array I mean something like "var arrayThing = x", i want it to return the string "arrayThing". As for my previous code, I think it is completely unrelated so I doubt it would help.Tet– Tet2018-09-12 12:28:50 +00:00Commented Sep 12, 2018 at 12:28
Add a comment
|
3 Answers
You can set the name of an array explicitly like so
var arr = []
arr.name = "arr"
and refer to it later as so
console.log(arr.name)
BUT there's a problem with this- array declaration in javascript is essentially just a pointer to some location in memory. Several other variables could have the a different 'name' assigned to them, but all still point to the same array.
3 Comments
Tet
Is this the only way to get the name of a array(State it beforehand)?
mic
See the answer by @KaomiDev, as it's better than mine. But just remember, this is not a great solution to your problem and will likely cause issues in the future.
Tet
Thanks, I will keep that in mind if I run into problems with it.