Skip to content Skip to sidebar Skip to footer

Unable To Filter The Non Empty Array Data Using Lodash Filter

An array is as follows : const arr = [ { name: 'Aditya', hobbies: ['Football', 'Basketball'] }, { name: 'Amitabh', hobbies: [] }, { name:

Solution 1:

The predicate (second argument) of _.filter indicates the property or properties to filter. Since hobbies is a string array, there is no hobby property of hobbies.

You can use Array.prototype.includes like this:

const data = _.filter(arr, item => item.hobbies.includes('Unclear'));

// If you want to extract just the 'hobbies' object, not the parentconst hobbies = _.map(data, 'hobbies');

Post a Comment for "Unable To Filter The Non Empty Array Data Using Lodash Filter"