How to know if two arrays have the same values
问题 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