Lodash – reject method

Lodash - reject method

Syntax Of Lodash reject method

_.reject(collection, [predicate=_.identity])

The opposite of _.filter; this Lodash reject method returns the elements of the collection that predicate does not return truthy for.

Arguments

  • collection (Array|Object) โˆ’ The collection to iterate over.
  • [predicate=_.identity] (Function) โˆ’ The function invoked per iteration.

Output

  • (Array) โˆ’ Returns the new filtered array.

Example

var _ = require('lodash');
var users = [
   { user: 'Joe', age: 48, active: false },
   { user: 'Robert', age: 34, active: true },
   { user: 'Julie', age: 40, active: false },
   { user: 'Stafey', age: 36, active: true }
];
var result = _.reject(users, ['active', false]);
console.log(result);

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

[
   { user: 'Robert', age: 34, active: true },
   { user: 'Stafey', age: 36, active: true }
]

Next Topic – Click Here

This Post Has 2 Comments

Leave a Reply