Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

133
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda