Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

343
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!