Removing duplicates from list, array

I’m struggling with this. Can someone help me with coding a filtered list or updating a current list to remove duplicates?
Example: var list = [“a”, “b”, “c”, “a”, “a”, “d”]
What would be code to update list or create a new one that has
list = [“a”, “b”, “c”, “d”] and remove the duplicates “a”

  1. Create a variable: newList and assign it to an empty list:
  2. Run a for loop through the list with the duplicates:
    for(var i = 0; i != list.length; i++){

}
3. Here’s what you should be doing in that for loop:
Check if the current list element (list[i]) is in newList. Here’s how you can check that: newList.indexOf(list[i]) != -1 . If this is true, then the value is in the list. Otherwise, its not. Then, create an if statement. If that expression is false, then you need to add that value into the list. Otherwise, dont do anything. newList is list now, but without duplicates

2 Likes

Thank you so much! It works!

Glad I could help, sorry for the few mistakes in my explanation. I was hurrying because I wouldn’t have access to internet very shortly after I had written the answer.