I need to write a function to remove the remaining items of an existing one in an array – in console returns to me [ 1, 2, 2, 3 ] instead [1,2,3]. I don’t find my mistake.
function removeRemainItemArray(arr) {
var new_arr = [];
for (var i = 0; i < arr.length; i++) {
if (arr[i] in new_arr) {
continue
} else {
new_arr.push(arr[i])
}
}
return new_arr
}
console.log(removeRemainItemArray([1, 2, 2, 2, 2, 3, 3, 1, 3, 2]))