Skip to content

Instantly share code, notes, and snippets.

@vermie
Created June 25, 2015 23:49
Show Gist options
  • Save vermie/79eeaed5ab048c8d2004 to your computer and use it in GitHub Desktop.
Save vermie/79eeaed5ab048c8d2004 to your computer and use it in GitHub Desktop.
function hasIndex(array, index) {
return array.splice(index, 1).reduce(function () {
return true;
}, false);
}
var array = [];
hasIndex(array, 0); // => false
array[0] = 1;
hasIndex(array, 0); // => true
array[0] = undefined;
hasIndex(array, 0); // => true
array[2] = 1;
hasIndex(array, 1); // => false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment