Skip to content

Instantly share code, notes, and snippets.

@renarsvilnis
Last active May 16, 2016 21:21
Show Gist options
  • Save renarsvilnis/b0fef6565d5c62e12826 to your computer and use it in GitHub Desktop.
Save renarsvilnis/b0fef6565d5c62e12826 to your computer and use it in GitHub Desktop.
/**
* ES6 way of removing nth array element in an immutable way
* @param [Array] arr
* @param [number] i
* @return [Array]
*/
function removeNthEl (arr, i) {
return [
...arr.slice(0, i),
...arr.slice(i + 1)
];
};
removeNthEl([1, 2, 3], 2);
// > [1, 2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment