I just want to ask if the in_array_orig and in_array_new is just the same. and also im confused on the result when comparing both array (<
Yes, there are differences between the two.
Firstly, the syntax for(var i=0; i
But the real differences come down to how Javascript treats arrays and objects.
Using for(x in y)
causes JS to loop through all properties and methods in an object.
In JS, an array is simply a type of object, with a few pre-defined methods and properties, such as length
to find the number of array elements, pop()
and push()
to add and remove elements, etc.
If you use the for(x in y)
syntax on an array, it will include some of these methods and properties in the loop. This is unlikely to be what you intended, and could cause some odd side effects.
Therefore, if you want to use for(x in y)
, you are better off starting with an object rather than an array.
I hope that helps.