Javascript: Check Arrays Are Equal

Use this simple function to check arrays in javascript are equal:
function areEqualArray(array1, array2) {
  if (array1.length != array2.length) {
    return false;
  }
  // sort -> join -> compare as string
  return array1.sort().join() == array2.sort().join();
}