remove element from array in an immutable way

Solutions on MaxInterview for remove element from array in an immutable way by the best coders in the world

showing results for - "remove element from array in an immutable way"
Dario
29 Mar 2016
1const arr = ['a', 'b', 'c', 'd', 'e'];
2
3const indexToRemove = 2; // the 'c'
4
5const result = [...arr.slice(0, indexToRemove), ...arr.slice(indexToRemove + 1)];
6
7console.log(result);
8// ['a', 'b', 'd', 'e']