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

168
Views
Getting specific value for every row from multiple rows

I have a code for fetching multiple selected rows. I can get all the rows of data but I am planning to get specific data that is merited. I'm stuck on getting the specific value of merits of each selected row and wanting to do code for their median. Please advise.

const median = {{ employeesTable.selectedRow.data }}
return median

Here is a sample data and what I'd like to get is only the merits which is 10 and 14 for example and get their median.

[{
   id:"15"
   email:"cornflakes123@gmail.com"
   employee_name:"Mark"
   merits:10
},
{
   id:"12"
   email:"fourleaves@gmail.com"
   employee_name:"Grey"
   merits:14
}]

My desired output to be showing is the median of the merit/s being selected. For example if three rows are selected, their merits are gathered and then given a median.

Example, if the three rows are having the merits of 5, 11 and 12 then the my desired output is to show the median 11 on ''return'' value.

almost 4 years ago · Santiago Trujillo
2 answers
Answer question

0

UPDATE 2

Getting the median with the following function (thanks goes to https://stackoverflow.com/a/53660837/8820118):

let data = [
      {
        id: "15",
        email: "cornflakes123@gmail.com",
        employee_name: "Mark",
        merits: 1,
      },
      {
        id: "12",
        email: "fourleaves@gmail.com",
        employee_name: "Grey",
        merits: 5,
      },
            {
        id: "12",
        email: "fourleaves@gmail.com",
        employee_name: "Grey",
        merits: 100,
      },
            {
        id: "12",
        email: "fourleaves@gmail.com",
        employee_name: "Grey",
        merits: 100,
      },
                  {
        id: "12",
        email: "fourleaves@gmail.com",
        employee_name: "Grey",
        merits: 500,
      },
    ]

function median(myData) {
    const sorted = Array.from(myData.map((item) => item.merits)).sort((a, b) => a - b);
    const middle = Math.floor(sorted.length / 2);

    if (sorted.length % 2 === 0) {
        return (sorted[middle - 1] + sorted[middle]) / 2;
    }

    return sorted[middle];
}

console.log(median(data));

UPDATE

Based on your comment you want to return the lowest merit value from your array.

const data = {{ employeesTable.selectedRow.data }}

//now that we have the data we can get min and max value
let min = Math.min(...data.map(item => item.merits));
let max = Math.max(...data.map(item => item.merits));

return min; //or return max

OLD POST

Just select the key from your object. Here is a little example based on your provided code:

const employeesTable = {
  selectedRow: {
    data: [
      {
        id: "15",
        email: "cornflakes123@gmail.com",
        employee_name: "Mark",
        merits: 10,
      },
      {
        id: "12",
        email: "fourleaves@gmail.com",
        employee_name: "Grey",
        merits: 14,
      },
    ],
  },
};

//iterate over the array
for (let i = 0; i < employeesTable.selectedRow.data.length; i++) {
  console.log(getMerits(i)); //return merit for that entry
}

function getMerits(index) {
  return employeesTable.selectedRow.data[index].merits;
}

Please give more details as your question can mean something else, for example only retrieving those with value 10 and 14. In that case provide more informations what you are trying to achieve.

almost 4 years ago · Santiago Trujillo Report

0

employeesTable.selectedRow.data.forEach((ele)=>{
  console.log(ele.id)
})
almost 4 years ago · Santiago Trujillo 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!