I'm not clear on the correct syntax to do the following.
- I have tried eval() I have tried [] and {[]} as well..
I start with this:
var player1InitStart = 0;
var player2InitStart = 0;
var player3InitStart = 0;
var player4InitStart = 0;
var playerID = event.target.id; // will return, player1, 2, 3, 4
To be used in a check like so:
if(eval(playerID + "InitString") == 0){
//do something, first time starting video
eval(playerID + "InitString") = 1;
alert('First Time Playing Video' + eval(playerID + "InitString"));
}
I am trying to use the playerID value together with the string: "InitStart"..
so I can then update the target xxInitStart variable above.
How can I concatenate the var playerID with the string InitStart so I can now target one of the playerXInitSTart variables to update it?
Update: answer/solution that worked for me-
- no clue why the $ character is being used? (reminds me of PHP)
no clue why the back tick marks '
' are there either? '
'var playerID = event.target.getIframe().id; var targetInitID =
${playerID}InitStart
;//access (get or set) alert(window[targetInitID]); window[targetInitID] = 1;