I am trying to compare two arrays are they equal or not. I am breaking the array a
and finally storing them into two different arrays b
and c
. At last, I am checking the array b
and c
in the console.
Console shows equal values but when I compare two arrays then I am getting the array are not equal.
Here is my code :
var a = [1,2,3,4,3,2,1];
var b = [];
var c = [];
var t = 0;
var length = a.length;
console.log("is the array length" + length);
if (length %2 !== 0) {
var mid = parseInt(length/2)-1;
console.log(a[mid]);
for(var j=length-1; j>(mid+1); j--) {
c[t] = a[j];
t++;
}
for(var i=0; i<=mid; i++) {
b[i] = a[i];
}
console.log(c);
console.log(b);
if(b == c) { //comparing the array b and c
console.log("true");
}
else {
console.log("no")
}
}
Here is my jsbin link : https://jsbin.com/metexuruka/edit