In the example you have posted, the two uses are the same. Both append a new element to the end of the array.
However, the push()
method can take multiple arguments and so you can append multiple elements to the end of the array in one statement. push()
then returns the new length of the array. push()
is also shorter and arguably easier to read.
Another thing to consider is that if thisarray
has been incorrectly defined (ie. it is not an Array object) then thisarray[thisarray.length] = int;
is likely to fail silently since .length
will simply be undefined
. Whereas thisarray.push(int)
will fail with a trappable TypeError exception.
Regarding PHP's thisarray[]
(square bracket) syntax. There is nothing quite the same in JavaScript, as far as syntax goes. However, thisarray[thisarray.length] = int;
performs the same action.