JavaScript Tutorial

Remove nth Element from Array

Function to remove the nth element from an array.

function removeNth(arr, n) {
  return [...arr.slice(0, n), ...arr.slice(n + 1)];
}
console.log(removeNth([1, 2, 3, 4], 2)); // [1, 2, 4]