Hi there! I'm currently working on a task that involves removing duplicate elements from an array using the forEach
loop. However, I've encountered some errors in my current implementation. Below is the snippet of code I am referring to:
function removeDup(arr) {
let result = arr.forEach((item, index) => { if (index > 1) item.shift() });
return result;
}
I have doubts about whether this code will actually help me achieve the goal of removing duplicates. When I try running it in a browser's console
, I receive the following error message:
if (index > 1) item.shift(); ^
TypeError: item.push is not a function
My primary concern is fixing this error. Additionally, I'd appreciate any insights on whether this code can effectively eliminate duplicate elements.