When you need to remove a value present multiple times in the array(e.g. [1,2,2,2, 4, 5,6]).
function removeFrmArr(array, element) {
return array.filter(e => e !== element);
};
var exampleArray = [1,2,3,4,5];
removeFrmArr(exampleArray, 3);
// return value like this
//[1, 2, 4, 5]
You can use splice to remove a single element from the array but splice can't remove multiple similar elements from the array.
function singleArrayRemove(array, value){
var index = array.indexOf(value);
if (index > -1) array.splice(index, 1);
return array;
}
var exampleArray = [1,2,3,4,5,5];
singleArrayRemove(exampleArray, 5);
// return value like this
//[1, 2, 3, 4, 5]