javascript - Increment variable based on global variable -


what want following code

$floorno = 1; // current floor  if ($floorno == 1){   $number1++; } else if ($floorno == 2){   $number2++; } ... 

etc.

is there shorter version, ($number+$floorno)++; ?

you use array:

var arr = [1, 2, 3]; var floorno = 1; arr[floorno]++; // = [1, 3, 3] 

if floorno entered user, can use modulo operator ensure it's valid:

arr[floorno % arr.length]++; // = [1, 3, 3] 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -