assign multiple variables to the same value in Javascript

前端 未结 5 2015
Happy的楠姐
Happy的楠姐 2020-11-30 18:40

I have initialized several variables in the global scope in a JavaScript file:

var moveUp, moveDown, moveLeft, moveRight;
var mouseDown, touchDown;
         


        
5条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 19:05

    Put the varible in an array and Use a for Loop to assign the same value to multiple variables.

      myArray[moveUP, moveDown, moveLeft];
    
        for(var i = 0; i < myArray.length; i++){
    
            myArray[i] = true;
    
        }
    

提交回复
热议问题