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

157
Views
How does one retrieve all values from a specific named column from an array of table row like objects?

The following variable refers to a table like object structure.

const jstable = [{
  "date": "2022-02-08",
  "new_cases": "23100",
  "deaths": "75",
  "recovered": "30294"
}, {
  "date": "2022-03-01",
  "new_cases": "25854",
  "deaths": "78",
  "recovered": "25548"
}];

I need to store/push e.g. all values of column date into another array. How could this be achieved?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

While you can do this with a loop and a collector array, the cleanest way to do it is with map:

let dates = jstable.map(row => row.date);

However, if you need to create arrays for multiple columns, map is not the best function to use because it will have to run through the array multiple times, once for each column you are trying to get.

about 4 years ago · Juan Pablo Isaza Report

0

You can loop through all the elements and get the right attribute.

const jstable = [{"date":"2022-02-08","new_cases":"23100","deaths":"75","recovered":"30294"},{"date":"2022-03-01","new_cases":"25854","deaths":"78","recovered":"25548"}];

function col(array, column){
  let result = [];

  for (let item of array) {
    result.push(item[column]);
  }
  return result;
}

console.log(
  col(jstable, 'date')
);
.as-console-wrapper { min-height: 100%!important; top: 0; }

And col(jstable, 'date') would get you all the date column values.

about 4 years ago · Juan Pablo Isaza Report

0

JSON.parse(jstable).map(row => row.date);

Is this what you're looking for?

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!