Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

remove element from array in an immutable way

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);
// ['a', 'b', 'd', 'e']
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #remove #element #array #immutable
ADD COMMENT
Topic
Name
9+4 =