Here is an example of my situation:
var list1 = ['apple', 'banana', 'orange'];
var list2 = ['carrot', 'lettuce', 'tomato'];
When I use:
alert(list1)
I get: apple, banana, orange
. This is correct.
Now, I want to get the name of the array from a different function. In this function, I loop through an array like this:
var allLists = [list1, list2]
for (i = 0; i < allLists.length; i++) {
alert(allLists[i]);
}
Currently, I see "apple, banana, orange" followed by "carrot, lettuce, tomato" in the alerts. What I actually want is to display the names of the arrays, not their contents. How can I achieve this?
My goal is to have two alerts showing: "list1" and "list2", the names of the arrays.