Underscore.js -.without/reject

Remove item from array

by Varun Nath

HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>

JavaScript

//to apply callback use reject 
var removeValue = function(array, id) {
    return _.reject(array, function(item) {
        return item === id;
    });
};
var array = [1, 20, 50, 60, 78, 90];
var id = 50;

console.log(removeValue(array, id)); // [1, 20, 60, 78, 90]
console.log(_.without(array, id)); // [1, 20, 60, 78, 90]