Last active
December 11, 2015 05:58
-
-
Save ourmaninamsterdam/4555503 to your computer and use it in GitHub Desktop.
Finds and removes item from array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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