Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

225
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda