given 2 arrays,
var x =[ 1, 3, 4,6,8 9];
var y =[1, 3,4, 9, 4,7];
how do i compare x and y? at the specific index eg x[0] vs y[0], x[1] vs y[1]
to get an output. [1, 3,4]
x.filter((e, i) => e === y[i])
2 Likes
Kril’s answer is the way to go! If you want a more verbose version, this is the same thing:
x.filter(function (e, i) {
return e === y[i];
});
1 Like
var a = [1,2,3,5,5, 8];
var b = [1,2,3,7,5, 8]
for(i=0;i<a.length;i++){
if( a[i]==b[i]){}
}
i actually did it this way. it works