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

126
Vistas
create a new array from the keys of an Array's Object

I have a array of objects, and by using the foreach or map I want to create new array from its keys:

[{
    "name": "Dentist Specialist",
    "category": "Roles",
    "path": "cde"
},
{
    "name": "Root Canal Therapy",
    "category": "Procedures",
    "path": "abc"
},
{
    "name": "Live Course",
    "category": "Course Type",
    "path": "mfg"
}]

From the above array I need a new ARRAY which will look like this:

[{
    "Roles": "Dentist Specialist"
},
{
    "Procedures": "Root Canal Therapy"
},
{
    "Course Type": "Live Course"
}]

Just replace the 2nd key with the first key and remove the rest.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use map here to achieve the desired result.

arr.map(({ category, name }) => ({ [category]: name }));

or

arr.map((o) => ({ [o.category]: o.name }));

const arr = [
  {
    name: "Dentist Specialist",
    category: "Roles",
    path: "cde",
  },
  {
    name: "Root Canal Therapy",
    category: "Procedures",
    path: "abc",
  },
  {
    name: "Live Course",
    category: "Course Type",
    path: "mfg",
  },
];

const result = arr.map((o) => ({ [o.category]: o.name }));
console.log(result);

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