Question: I want to remove an element (an array) from an array (an array of arrays).

```
car = [carId, brand, year]; //array
selectedCars = []; //array of arrays

```

This is what i have tried, but the comparison never gets true, although it should.

```
function removeElementFromArray(carsArray, car){
    var i;
    for(var k = 0; k < carsArray.length; k++){
        if(carsArray[k][0] == car[0]){
            i=k;
        }
    }

    var index = carsArray.indexOf(i);
    if(index != -1) {
        carsArray.splice(index, 1);
    }
}

```

Answer: 
`carsArray.indexOf(i)` will never find anything. `carsArray` is an array of arrays, `i` is the index where a match was found, not an array.

You don't need to call `indexOf()`, the `for` loop already found the index you want. You just need to test whether it found anything.

```
if (index !== undefined) {
    carsArray.splice(index, 1));
}

```

You also should put `break;` in your loop, so you stop searching once you find a match.

In fact, you could just do the splice in the loop.

```
for (var i = 0; i < carsArray.length; k++) {
    if (carsArray[k][0] == car[0]) {
        carsArray.splice(k, 1);
        break;
    }
}

```
You can try using the array `.every` method for your comparison, along with `.findIndex` if you can use es6:

```js
car = ["carId", "brand", "year"]; //array
selectedCars = [["carId", "brand", "year"], ["otherCarId", "brand", "year"]]; //array of arrays

function removeCar(selected, car) {
    const index = selected.findIndex(selectedCar => selectedCar.every((val, i) => val === car[i]));
    if (index !== undefined) selected.splice(index, 1);
    return selected;

}

console.log(selectedCars);
removeCar(selectedCars, car);
console.log(selectedCars);
```