0

I currently have an array of already declared variables so I can go through them with a for loop. (These variables are declared in adobe captivate so I can't really go about changing them). Passing them back and forth is a bit of a problem however as the array is just storing the actual values of the variables. Here's a simplified example:

Already declared variables: item1viewed,item2viewed,item3viewed;

My added code:

var array = new Array[item1viewed,item2viewed,item3viewed];

for (i=0;i<array.length;i+=1)
{
array[i]=1;
}

how can I pass these over to the already declared variables?

DPppr
  • 1
  • This array doesn't contain your 'declared variables'. It contains copy of their values. – Emre Acar Nov 04 '14 at 10:30
  • Do you want all your "Declared variables" to be 1 as you have done at the bottom of your code? I am confused! – ha9u63a7 Nov 04 '14 at 10:32
  • Yeah - as I said its a simplified version of the code - the for loop will change all the values in the array to 1 but I need that to be passed back to the previously declared variables. – DPppr Nov 04 '14 at 10:40
  • you can't, not with the design you've given. – Keith Nicholas Nov 04 '14 at 10:44
  • You may get more useful advice if you explain more about what you are trying to do and why you need to change the values. – Stuart Nov 04 '14 at 20:14
  • Essentially it's for creating a string of suspend data using the value of each variable so you'd just need to fill the array with the variable names and it would handle the rest. It needs to work both ways though so item1viewed = 0,item2viewed = 1, item3viewed = 1 would give me the string "011" but then on revisiting "011" would need to populate those variables. I have done it manually for now. – DPppr Nov 06 '14 at 16:29

1 Answers1

0

You can't do it quite that way.... I have no idea what you are trying to do, but ONE way that similar...

var viewed = {
   item1: 0,
   item2: 0,
   item3: 0,
}

var array = new Array('item1', 'item2', 'item3')

for (i=0;i<array.length;i+=1) {
  viewed[array[i]]=1;
}
Keith Nicholas
  • 43,549
  • 15
  • 93
  • 156