0

Let's say I have the following for loop in Javascript (this is for Adobe Photoshop using ExtendScript):

http://prntscr.com/cx2cab

Would it be possible to rewrite this so that all six of the created created text fields are all assigned as six different variables, each with a constant name only differing by "i" as specified in the for loop? Furthermore, would it then be possible to assign all of those variables into an array within the for loop instead of writing out each variable name in the array individually? If so, how would you go about this?

asked Oct 21, 2016 at 11:20
1
  • Please copy the code and paste it here using the proper formatting to help other users understand what you're trying to achieve. Commented Oct 21, 2016 at 11:41

1 Answer 1

1

You can create window variables window["num"] = "1" == var num = "1"

var p = ["I","You","We","They"];
for(var i=0;i<p.length;i++){
window[p[i]] = p[i]+" "+"Love Cacke";
}
//now you have variables I,You,We,They
console.log(I);
console.log(You);
console.log(We);
console.log(They);
/*
[
 "I Love Cacke",
 "You Love Cacke",
 "We Love Cacke",
 "They Love Cacke"
]
*/

answered Oct 21, 2016 at 11:52
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.