var array1 = [\'a\',\'b\',\'c\',\'d\'];
var array2 = [\'a\',\'v\',\'n\',\'d\',\'i\',\'f\'];
var array3 = [\'1\',\'2\',\'3\',\'4\',\'5\',\'6\'];
Just s
Use Array.prototype.reduce to check the duplicates and create a new array - see demo below:
var array1 = ['a','b','c','d'];
var array2 = ['a','v','n','d','i','f'];
var array3 = ['1','2','3','4','5','6'];
var result = array2.reduce(function(p,c,i){
if(array1.indexOf(c) !== -1) {
p.push(array3[i]);
} else {
p.push(c);
}
return p;
},[]);
console.log(result);