Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
Using Lodash chaining, how can I return a filtered array of objects while mapping over an object of arrays

I've got object of filters that look like this:

var filterUpdate = {
 assetClass: [{id: 1, name: 'photo'}, {id: 2, name: 'thumbnail'} ]
 vehicleType: [{id: 1, name: 'nissan'}]
}

I've got state data like this (the keys representing years are dynamic and can change):

this.state.filteredOwnership = {
 2020: [],
 2021: [{assetClass: 'thumbnail', vehicleType: 'Toyota' }, {assetClass: 'Abs', vehicleType: 'Prius' }]
 2022: [{assetClass: 'thumbnail', vehicleType: 'Toyota' }, {assetClass: 'photo', vehicleType: 'Prius' }, {assetClass: 'Abs', vehicleType: 'nissan'}, {assetClass: 'LMO', vehicleType: 'Tesla'} ]
}

This is the present lodash chain:

const filterData = _filter(filteredOwnership, (dataitem)=> {

  if(_isEmpty(filterUpdate.assetClass) && _isEmpty(filterUpdate.vehicleType)) {
    return dataitem
  }

  if(_some(_map(filterUpdate.assetClass, 'name'), dataitem.assetClass)  || _some(_map(filterUpdate.vehicleType, 'name'), dataitem.vehicleType)){
    return dataitem
  }
  
}); 

We want to return a filtered array that would look like this:

filterData = {
   2020: [],
   2021: [{assetClass: 'thumbnail', vehicleType: 'Toyota' }]
   2022: [{assetClass: 'thumbnail', vehicleType: 'Toyota' }, {assetClass: 'photo', vehicleType: 'Prius' }, {assetClass: 'Abs', vehicleType: 'nissan' } ]
}

The problem I'm having is that dataitem.assetClass and dataitem.vehicleType are the array of objects from within the year keys. I don't know where to use _map on dataitem that would help me return an item with in that array to be filtered

I am also open to non lodash suggestions! Regular js ways to do it would also be appreciated!

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!