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

161
Views
How to Filter object and get certain field in Javascript

I'm struggle with using filter.

Initial object
This is my object.

[{
  isOpen : true,
  items : [
    {itemId : '', name : 'some name'},
    {itemId : 'new', name : 'new name'}
  ]
},]

Expected Result

I just want to show that the itemId is not an empty string and also isOpen field.

[{
  isOpen : true,
  items : [
    {itemId : 'new', name : 'new name'}
  ]
},]

What I try

  const removeEmptyStringInItems = (item) => item.items?.filter((v) => v.itemId);
  const finalItems = myItems.map(removeEmptyStringInItems);

output.

{itemId : 'new', name : 'new name'}

Any ideas for this problem? I really need help!

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

0

you could try update the code to this to keep the finalItems format same as the initial value

const removeEmptyStringInItems = (items = []) => items?.filter((v) => v.itemId);
const finalItems = myItems.map((v) => ({...v, items: removeEmptyStringInItems(v.items)}));
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!