What is the cleanest way to remove an element from an immutable array in JS? [duplicate] What is the cleanest way to remove an element from an immutable array in JS? [duplicate] reactjs reactjs

What is the cleanest way to remove an element from an immutable array in JS? [duplicate]


You can use a combination of spread and Array#slice:

const arr = ['a', 'b', 'c', 'd', 'e'];const indexToRemove = 2; // the 'c'const result = [...arr.slice(0, indexToRemove), ...arr.slice(indexToRemove + 1)];console.log(result);