How to select all other values in an array except the ith element with JavaScript?

To select all other values in an array except the ith element with JavaScript, we use the filter method.

For instance, we write

const items = [1, 2, 3, 4, 5, 6];
const current = 2;
const itemsWithoutCurrent = items.filter((x) => {
  return x !== current;
});

to call items.filter with a callback that checks if x isn’t equal to current and return all the elements in items where x isn’t equal to current.