Question: [Array.prototype.splice()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice) allows to remove multiple elements from array but if and only if theese elements are siblings. But what if no?

Suppose, we need to remove 2th, 5th and 8th elements from array (cont from 0).

```js
const targetArray = [ "alpha", "bravo", "charlie", "delta", "echo", "foxtrot", "golf", "hotel", "india" ];
const indexesOfArrayElementWhichMustBeRemoved = [ 2, 5, 8 ];

for (const [ index, element ] of targetArray.entries()) {

    if (indexesOfArrayElementWhichMustBeRemoved.includes(index)) {
        // remove
    }

}

```

Once we removed one element, the array will change and 5th element will not be 5th anymore.

Other approach is make elements empty first, and then remove empty elements:

```js
for (const i = 0; i < targetArray.length; i++)  {
    if (indexesOfArrayElementWhichMustBeRemoved.includes(i)) {
        delete targetArray[i]
    }
}

for (const [ index, element ] of targetArray.entries()) {
    if (typeof element === "undefined") {
        targetArray.splice[index, 1]
    }
}

```

But this methodology does not match with "one pass" requirement and also will delete the element which had
"undefined" value initially.

Answer: 
You could use [filter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter), like this:

```js
const sample = ['a', 'b', 'c', 'd', 'e', 'f']
const idx = [1, 3, 5];
const result = sample.filter((x, i) => idx.includes(i));
console.log(result);
```

Or if you want to specify which elements to remove, just do `!idx.includes(i)`.

If mutating the original array is a requirement, then the best technique is usually to iterate over the array backwards, and remove as you go. That changing indexes don't matter as much.

```
for(let i=array.length-1;i>=0;i--){
  // if ... array.splice
}

```
You can increment all values in the array indexesOfArrayElementWhichMustBeRemoved by one each time you delete the index.

```js
for (const [ index, element ] of targetArray.entries()) {

    if (indexesOfArrayElementWhichMustBeRemoved.includes(index)) {
        // remove and increment all values in indexesOfArrayElementWhichMustBeRemoved
    }

}

```

Or you could create a counter which will get incremented each time you delete.

```js
let counter = 0
for (const [ index, element ] of targetArray.entries()) {

    if (indexesOfArrayElementWhichMustBeRemoved.includes(index + counter)) {
        // remove and increment counter value by 1
    }

}

```