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

224
Views
How to use the filter method in javascript?

I am using filter method to get a selected item from an option list. But it gives me the following error:

Array.prototype.filter() expects a value to be returned at the end of arrow function.eslintarray-callback-return

My function is the following:

const getSelectValue = () => {
  const selectedList = get(state, `${name}`, []);
  if (isEmpty(selectedList) || isEmpty(options)) {
    return [];
  }
  const selectedSet = new Set(selectedList);
  return options.filter((item) => {
    if (item.value !== "Add type") return selectedSet.has(item.value);
  });
};

Anyone who can spot the missing thing here?

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

0

The arrow function supplied as filter callback should always return some value by this linting rule. But here...

item => {
  if(item.value !=="Add type") {
    return selectedSet.has(item.value); 
  }
);

... there are no return statements if if condition is falsy; hence the error. You can fix this in many different ways; the most straightforward one is just adding explicit return false; at the end of the function. Another approach is combining two conditions:

item => {
  return item.value !=="Add type" && selectedSet.has(item.value) 
}
about 4 years ago · Juan Pablo Isaza Report

0

Just return a value if statement is false (after if } enclosing bracket) and error should be gone.

about 4 years ago · Juan Pablo Isaza Report

0

you have to change like this :

const getSelectValue = () => {
        const selectedList = get(state, `${name}`, []);
        if (isEmpty(selectedList) || isEmpty(options)) {
            return [];
        }
        const selectedSet = new Set(selectedList);
        return options.filter(item => {
           
                return item.value !=="Add type" && selectedSet.has(item.value); 
        }  );
    };
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!