Q:

How to delete repeating strings from an array by indexes?

I have an array with color names:
var colors = ["yellow","yellow","yellow","orange","orange","blue","blue","blue","blue];

And an array with indexes:
var indexes = [2, 3];

I would like to remove color names on the positions given by indexes – in this example the third "yellow" and the first "orange". I tried a loop like this:
for (var i = colors.length - 1; i >= 0; i--) {
    for (var j = 0; j < indexes.length; j++) {
        if (colors.indexOf(colors[i]) == indexes[l]) {
            colors.splice(k, 1);
        }
    }
}

The trouble is that colors.indexOf(colors[i]) gives the same value for all repeating color names. Is there a better way?

A:

Try creating a new array:
var colors = ["yellow","yellow","yellow","orange","orange","blue","blue","blue","blue"];
var newcolors=[];
colors.forEach(function(item) {
    if(newcolors.indexOf(item)==-1)
    {
        newcolors.push(item);
    }
})
colors = newcolors;

