Question: I have these two arrays: one is filled with information from an ajax request and another stores the buttons the user clicks on. I use this code (I filled with sample numbers):

```
var array1 = [2, 4];
var array2 = [4, 2]; //It cames from the user button clicks, so it might be disordered.
array1.sort(); //Sorts both Ajax and user info.
array2.sort();
if (array1==array2) {
    doSomething();
}else{
    doAnotherThing();
}

```

But it always gives `false`, even if the two arrays are the same, but with different name. (I checked this in Chrome's JS Console). So, is there any way I could know if these two arrays contain the same? Why is it giving `false`? How can I know which values in the first array are not in the second?

Answer: 
When you compare those two arrays, you're comparing the objects that represent the arrays, not the contents. 

You'll have to use a function to compare the two. You could write your own that simply loops though one and compares it to the other after you check that the lengths are the same.
Simple solution for shallow equality using ES6:

```
const arr1test = arr1.slice().sort()
const arr2test = arr2.slice().sort()
const equal = !arr1test.some((val, idx) => val !== arr2test[idx])

```

Creates shallow copies of each array and sorts them. Then uses `some()` to loop through `arr1test` values, checking each value against the value in `arr2test` with the same index. If all values are equal, `some()` returns `false`, and in turn `equal` evaluates to `true`.

Could also use `every()`, but it would have to cycle through every element in the array to satisfy a `true` result, whereas `some()` will bail as soon as it finds a value that is not equal:

```
const equal = arr1test.every((val, idx) => val === arr2test[idx])

```