Tuesday 15 March 2011

very simple, javascript arrays syntax -


I have a very simple JS array, my normal canvas game is behaving differently when I have a block The code changed with another. Can you see them and see why they are working each other, and perhaps provide a suggestion? I may need 20+ items for these arrays, so I'm looking for a more condensed style.

This is one, which is enough to work for me, but is not running properly:

  var srd = new array (1,1,1 ); Var sw = new array (0,0,0); Var sang = new array (0,0,0); Var sHealth = new array (20,20,20);   

And then the original one, which is long but works fine:

  var srd = new array (); Srd [1] = 1; Srd [2] = 1; Srd [3] = 1; Var sw = new array (); Sw [1] = 0; Sw [2] = 0; Sw [3] = 0; Var sang = new Array (); Sung [1] = 0; Sung [2] = 0; Sung [3] = 0; Var sHealth = new array (); SHealth [1] = 20; SHealth [2] = 20; SHealth [3] = 20;    

You should do this ... values ​​are stored in ARA such as The first one is 0 and so on. Therefore 1 value will be used as ...

  var x = abc [0]; // The first value of the array ABC is being assigned to x   

do this (You see that I actually read your question and this is the same Which you like)

  var srd = [', 1,1,1]; Var sw = ['', 0,0,0]; Var sang = ['', 0,0,0]; Var sHealth = ['', 20,20,20];   

You can declare an array in JavaScript like this

var x = []; ------------- Literally - A shortcut to it has been provided by JS so that it can declare something as an array.

var x = new array; --Air Constructor

Literal

  • Searching for Object Terms
  • Function property prototype

    You can also do this:

    var x = 1, y = 2, z = 3, f;

    var b = some || {}; \\ A copy of the object is created which is called something, if it is not, then an empty object is formed.

No comments:

Post a Comment