How to compare two arrays in JavaScript and return a new array indicating matches -
this question has answer here:
is there way compare 2 arrays , return new array indicating values matched?
for example
a = ['africa', 'america', 'europe'] b = ['africa', 'asia', 'europe'] // need // c = [true, false, true] edit: far have
function mask(arr1, arr2) { var arr = []; (var = 0; < arr1.length; i++) { arr.push(arr1[i] === arr2[i]); } return arr; }
just loop through array. example:
var = ['africa', 'america', 'europe']; var b = ['africa', 'asia', 'europe']; var index = 0; var c = []; while(a.length > index){ c.push(a[index] === b[index]); index++ }
Comments
Post a Comment