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

156
Views
Filter Null/Undefined Values in React and ES6

I'm filtering null and undefined values so I don't need to pass variables that have null/undefined values. My problem is if my value is 0 I still want to pass it. Only null/undefined values should be filtered

const filterNonNull = (obj) => {
    return Object.fromEntries(Object.entries(obj).filter(([k, v]) => v));
  };
  
  export const printService = ({ person_id, print_count, group_id }) => {
    return getAxiosService().get(
      `print/${person_id}?${qs.stringify(filterNonNull({ print_count, group_id }))}`
    );
  };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Update your condition like .filter(([k, v]) => !(v === null || v === undefined))).

const filterNonNull = (obj) => {
    return Object.fromEntries(Object.entries(obj).filter(([k, v]) => !(v === null || v === undefined)));
};
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!