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

132
Visualizações
Flatten objects in array

Hey folks I am getting an array of objects from a response. I need to flatten all of the students objects to simply studentName but not certain how. Any help would be greatly appreciated.

Example Array:

[
 {
  students: {id: '123456', name: 'Student Name'},
  active: true
 },
 {
  students: {id: '123456', name: 'Student Name'},
  active: true
 }
]

What I am trying to do:

[
 {
  studentName: 'Student Name',
  active: true
 },
 {
  studentName: 'Student Name',
  active: true
 }
]
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

[
  { students: {id: '123456', name: 'Student Name'}, active: true }, 
  { students: {id: '123456', name: 'Student Name'}, active: true }
].map(e => ({studentName: e.students.name, active: e.active}))
about 4 years ago · Juan Pablo Isaza Relatório

0

You can loop through the array and set each item's students property to the name property of the students property:

const arr = [
 {students: {id: '123456', name: 'Student Name'},active: true},
 {students: {id: '123456', name: 'Student Name'},active: true}
]


arr.forEach(e => e.students = e.students.name)

console.log(arr)

about 4 years ago · Juan Pablo Isaza Relatório

0

map over the data and return a new object on each iteration.

const data=[{students:{id:"123456",name:"Student Name"},active:!0},{students:{id:"123456",name:"Student Name"},active:!0}];

const out = data.map(obj => {

  // Destructure the name and active properties
  // from the object
  const { students: { name }, active } = obj;
  
  // Return the new object
  return { studentName: name, active };
});

console.log(out);

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