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

95
Visualizações
Search objects for a given string

I have these objects

const data = [
  {
    id: 1,
    recipient: "001",
    assessment: "Apta",
    score: "2",
    ovarian: "E1",
  },
  {
    id: 2,
    recipient: "ABC2",
    assessment: "Apta",
    score: "2,5",
    ovarian: "E1",
  },
  {
    id: 3,
    recipient: "003",
    assessment: "Refugo",
    score: "3",
    ovarian: "E1",
  },
  {
    id: 4,
    recipient: "004",
    assessment: "Apta",
    score: "4",
    ovarian: "E2",
  },
];

And this is my code, which when it finds the correct string it returns me:

const searchAnimal = value => {
  setInput(value);

  JSON.parse(records).filter(item => {
    if (item.recipient === value) {
      setSearch([item]);
    }
  });
};

What would the logic be to return all object.recipients that start with 00? Would a regex maybe do it?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I think changing a little bit the logic would help:

let search = function (data, searchString) {
  return data.filter((item) => {
    return item.recipient.includes(searchString);
  });
};

By doing so will give you the object you're searching for.

about 4 years ago · Juan Pablo Isaza Relatório

0

You can filter for the objects with a recipient that starts with 00 by using:

const array00Animals = data.filter((animal) => animal.recipient.substr(0, 2) === '00');

This will return the array of objects but only id's 1, 3 and 4 from your sample data.

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