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: 
Object equality check:`JSON.stringify(array1.sort()) === JSON.stringify(array2.sort())`

The above test also works with arrays of objects in which case use a sort function as documented in <http://www.w3schools.com/jsref/jsref_sort.asp>

Might suffice for small arrays with flat JSON schemas.
If the order of the array elements are not important, you could try

```
function arraysEqual<T>(a:T[], b:T[]) {
  if (a === b) return true;
  if (a == null || b == null) return false;
  if (a.length !== b.length) return false;

  const aClone = [...a].sort();
  const bClone = [...b].sort();
  for (var i = 0; i < aClone.length; ++i) {
    if (aClone[i] !== bClone[i]) return false;
  }
  return true;
}

const arr1 = [1,2,3,4];
const arr2 = [3,2,1,4];
console.log(arraysEqual(arr1, arr2)) //true

```