Compare two array in javascript

var cubes = [ [1, 2, 3], [4, 5, 6], [7, 8, 9],];

var cubes2 = [ [10, 2, 3], [4, 5, 6], [7, 8, 9],];

var isIdentical=true;
for(var i = 0; i < cubes.length; i++) {
    var cube1 = cubes[i];
    var cube2 = cubes2[i];
    for(var j = 0; j < cube1.length; j++) {
        if(cube1[j]!=cube2[j])
        {
          isIdentical=false;
          alert('Both matrices are not equal'+"cube1[" + i + "][" + j + "] = " + cube1[j]+'!=='+"cube2[" + i + "][" + j + "] = " + cube2[j]);
          return;
        } else{
         //console.log("cube1i + "][" + j + "] = " + cube1[j]);
        }       
    }
}

if(isIdentical){
 alert('Both matrices are equal');
}

Leave a Reply

Your email address will not be published. Required fields are marked *