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

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

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 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