Why am I getting a string in an alert instead of a variable?

New Here ,
Aug 02, 2022 Aug 02, 2022

Copy link to clipboard

Copied

I'm working on some automation for a complex project.\

I think I have it mostly figured out:tttplacementCode2.jpg

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?

TOPICS
Actions and scripting , Cross-app workflows , Windows

Views

37

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Aug 02, 2022 Aug 02, 2022

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[
...

Likes

Translate

Translate
Adobe Community Professional ,
Aug 02, 2022 Aug 02, 2022

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

LATEST

Thank you so much! That worked perfectly!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines