const res = arr2.map(function(v) { for (let i = 0; i < arr1.length; i++) { if (v === arr1[i] && !this[i]) { this[i] = 1 return i } } }, {})