Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

232
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda