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

154
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

0

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

Is this what you're looking for?

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