Skip to content

Instantly share code, notes, and snippets.

@dbrockman
Created March 7, 2013 18:29
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dbrockman/5110478 to your computer and use it in GitHub Desktop.
Save dbrockman/5110478 to your computer and use it in GitHub Desktop.
JS array insertAt and removeAt function
function insertAt(arr, val, i) {
arr.splice(i, 0, val);
}
function removeAt(arr, i) {
return arr.splice(i, 1).length === 1;
}
function genericInsertAt(arr, val, i) {
Array.prototype.splice.call(arr, i, 0, val);
}
function genericRemoveAt(arr, i) {
return Array.prototype.splice.call(arr, i, 1).length === 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment