Variables in javascript switch cases? -


I want to use variables for each case in a switch statement, but it does not seem to work: Switch (Key) {Case key Next: // Go to next break; Case keypell: // Go to previous break; }

I really need a switch statement because, unlike this example, I have many different cases.

Why does not this work? Any work for this?

Edit : As stated in the answer, it is completely valid. I was using the properties of an object for each case, and there was a syntax problem with it.

You can use the variable to check, see the following example. You need to ensure that they have been announced and given a price. To see if the issue is happening elsewhere, you may need to look further to work with it.

  var keyNext = 1, // or "1" what you have, key = 2, key = key; // or key = 1 switch (key) {case key next: warning ('next'); break; Case key: Warning ('Previous'); break; }    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -