Skip to content

Instantly share code, notes, and snippets.

@hussainb hussainb/removeItem
Last active Aug 29, 2015

Embed
What would you like to do?
Remove Item From Array
function removeItem (array,toRemove){
var newArray = [];
for(var i=0;i<array.length;i++){
if(array[i]!=toRemove){
newArray.push(array[i]);
}
}
return newArray;
}
/*
Example
var inArr = [1,2,3,4,5];
var removeMe = 4;
var returnArr = removeItem (inArr,removeMe)
console.log(returnArr);
logs [1,2,3,5]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.