JqueryKing JqueryKing - 1 year ago 107
jQuery Question

How to Compare two Arrays are Equal using Javascript or Jquery?

I want position of the array is to be also same and value also same.

var array1 = [4,8,9,10];
var array2 = [4,8,9,10];

I tried like this

var array3 = array1 === array2 // returns false

Answer Source

You could use Array.prototype.every().(A polyfill is needed for IE < 9 and other old browsers.)

var array1 = [4,8,9,10];
var array2 = [4,8,9,10];

var is_same = (array1.length == array2.length) && array1.every(function(element, index) {
    return element === array2[index]; 


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download