Declare long list of variables quickly using Javascript without arrays? -


i know can use arrays there way declare multiple variables - lets 50 using loop , integer @ end of each variable going 1 every time.

<!doctype html> <html> <body>  <h1>javascript variables</h1>  <p id="demo"></p>  <script> var price1 = 5; var price2 = 6; var price3 = 7; var price4 = 8; var price5 = 4; var price6 = 1; var price7 = 9; var price8 = 8; var total = price1 + price2 + price3 + price4 + price5 + price6 + price7 + price8; document.getelementbyid("demo").innerhtml = "the total is: " + total; </script>  </body> </html> 

i know can use arrays

yes. , absolutely should use arrays purpose. designed for.

is there way declare mutiple variable quickly

only if create global variables. globals awful.

window["price" + i] = somevalue; 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -