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

159
Views
How to filter the following list using Lodash `_.filter()`

I have the following list named cart:

cart = [ {"state": "Canada", "id": "1"}, {"state": "USA", "id": "1"} ]
       

I have tried filtering it according to the following code where state should either be (USA, Canada), but its giving errors:

var oddNo = _.filter(cart, {'state': {"Canada", "USA"}, 'id': "1"});
console.log(oddNo);

What would be the correct way of doing it?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

i'm guessing this is loadash or underscore? the easiest way will be to pass a function as the second parameter that filters the array. _.filter(cart, (items) => {return item.state === 'USA' || item.state ==='Canada'}) check out the docs on lodash https://lodash.com/docs/4.17.15#filter

although really you probably dont need lodash for this and can just use native js filter https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter

about 4 years ago · Juan Pablo Isaza Report
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!