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

339
Visualizações
Reactjs i want to get the minumum price from this array list how can i get it

in reactjs im trying to this suppose my array list is something like this i want to get the minmum price from this list...suppose the 'totalll': 100 how can i do that please let me know. array->object->array->totalll

const data = [
  {
    name: "test",
    lab_partners: [
      {
        id: 0,
        totalll: 5000,
      },
      {
        id: 1,
        totalll: 200,
      },
      {
        id: 2,
        totalll: 1000,
      },
    ],
  },
  {
    name: "test",
    lab_partners: [
      {
        id: 0,
        totalll: 7000,
      },
      {
        id: 1,
        totalll: 100,
      },
      {
        id: 2,
        totalll: 800,
      },
    ],
  },
];

const minTotalByName = (data, id) => {
  const totals = data.filter((x) => x.lab_partners.find((y) => y.id === id));

  return Math.min(...totals);
};

const min = minTotalByName(data);
console.log(min, "min");
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

const totals = data
  .map((d) => d.lab_partners)
  .flat()
  .map((p) => p.totalll);
const minTotal = Math.min(...totals);

and you'll end up with 100 in minTotal.

If you need the full object with the lowest totalll, things get a little more complicated, but we can (for once with good conscience) use .reduce:

const lowestPartner = data
  .map((d) => d.lab_partners)
  .flat()
  .reduce(
    (currentMin, obj) =>
      !currentMin || obj.totalll < currentMin.totalll ? obj : currentMin,
    null,
  );
// {id: 1, totalll: 100}
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