If I have a list like this:
var a= [['1'[0]],['2'[0]],['3'[0]],['4'[0]]];
and if condition that should another variable be equal to either ‘1’,’2′,’3′,’4′ then to increment the values of their list eg:
for(var i=0; i<a; i++{
if(a[i] == z) {
a[i] += z;
}
}
I know the above code will not work, but how could I get each ‘inner’ element to incerment?
I’m a javascript novice, so please excuse any errors in the code.
Thanks
Those innermost arrays are at index
[1]of the first set of inner arrays, assuming your array’s actual format is:So you’re nearly there, you need to access
a[i][1][0]and incrememnt it++rather than+= z.Examples:
So for
z = '2':Then
z = '4':Here’s a demo on jsfiddle…
Update: This is where the updated value resides:
The
Array[1] 0: 1is the incremented value forz == '4'.