Copy link to clipboard
Copied
I'm working on some automation for a complex project.\
I think I have it mostly figured out:ttt
The problem is, my first alert opens a script alert popup that reads "Temp1" (without quotes) but my second alert opens a script alert popup that reads the value of Temp1 (which is the url I want).
Why does excelArray[0][i] return the declared variable, and not it's value?
That is because the value stored in the array is a string value. So in the alert it just prints the string that happens to be Temp. Now in the second alert you are asking it to alert the value of the variable Temp, so it uses its value. If you want to print the value in the first alert, you will have to instruct JS that you want to execute the value of the array and not use it literally, for that you could use eval method. See the following example
var temp = 5
var arr = ["temp"]
alert(eval(arr[
...
Copy link to clipboard
Copied
That is because the value stored in the array is a string value. So in the alert it just prints the string that happens to be Temp. Now in the second alert you are asking it to alert the value of the variable Temp, so it uses its value. If you want to print the value in the first alert, you will have to instruct JS that you want to execute the value of the array and not use it literally, for that you could use eval method. See the following example
var temp = 5
var arr = ["temp"]
alert(eval(arr[0])) //Execute value obtained from array. Prints 5
//Alternative to eval
var x = Function('return ' + arr[0])() https://stackoverflow.com/a/44103168
alert(x) //Prints 5
-Manan
Copy link to clipboard
Copied
Thank you so much! That worked perfectly!