views:

64

answers:

2
var a=[1,2,3];
var b=[3,2,1];
var c=new Array(1,2,3);

alert(a==b+"|"+b==c);

demo

how to check these array, and get true from equals method?

under jquery, has any methods for this?

thank you :)

+2  A: 

There are several prototype libraries out there that take the pain out of array functionality.

Try this one for many common array functions:

http://www.svendtofte.com/code/usefull_prototypes/

After including the script you will be able to call the following:

var array1 = (1,2,3);
var arrat2 = (1,2,3);
var equal = array1.compareArrays(array2);
Brian Scott
A: 

You should sort them and then loop over both of them to see if for the same index the value is different.

function compareNumbers(a, b)  {  
   return a - b;  
}  

a.sort(compareNumbers);
b.sort(compareNumbers);
Fabien Ménager