const colors=["red","green","blue","yellow"]; let index = colors.length - 1; while (index >= 0) { if (['green', 'blue'].indexOf(colors[index]) > (-1)) { colors.splice(index, 1); } index -= 1; }