MaxwellLynn MaxwellLynn - 2 years ago 73
Javascript Question

Remove value from array

I am trying to figure out how if you are adding values to an array and then the same value comes up you have push it to the same array to not push it up and remove the duplicate of the value from the array.

This is my code below:

if (!_.includes(scope.index, val)) {
} else {
_.remove(scope.index, val);

Answer Source

You have to call _.remove() with a predicate function which checks if the current element equals to val:

_.remove(arr, x=> x === val)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download