Skip to content

Instantly share code, notes, and snippets.

@ourmaninamsterdam
Last active December 11, 2015 05:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ourmaninamsterdam/4555503 to your computer and use it in GitHub Desktop.
Save ourmaninamsterdam/4555503 to your computer and use it in GitHub Desktop.
Finds and removes item from array
/**
* remove_from_array()
* Based on str param supplied, finds and removes matching item from array
* @param {Array} array Array to query
* @param {String} str String to look for
* @return {Bool} returns true after item is found and remove from array
*/
function remove_from_array(array, str) {
var i;
for(i = 0; i < array.length; i++){
if(array[i] === str){
array.splice(i, 1);
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment