How to use_.reject() Method in Javascript
The _.reject()
method is the opposite of _.filter()
, creating a new array with all elements that do not pass the test implemented by the provided function.
<!DOCTYPE html>
<html>
<head>
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js">
</script>
</head>
<body>
<script>
let array = [1, 2, 3, 4, 5];
let newArray = _.reject(array, function(item) {
return item === 3;
});
console.log(newArray);
</script>
</body>
</html>
Output:
[1,2,4,5]
Remove an Item from Array using UnderscoreJS
Underscore.js is a JavaScript library that provides a wide range of utility functions for working with arrays, objects, functions, and more. One common task when working with arrays is removing an item based on a specific condition. In this article, we will explore options to remove an item from an array using Underscore.js.
Table of Content
- Using _.without() Method
- Using _.filter() Method
- Using _.reject() Method