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

159
Vistas
JavaScript: Transform array of objects to an object

I am making an app that uses sequelize and the JSON value returned is:

[
  { key: 'PREFIX', value: 'm.' },
  { key: 'OWNER_ID', value: '14901414891498' },
  { key: 'GUILD_ID', value: '525219058950109' }
]

But I want to know if is possible to reorganize this json object to something like this:

{ prefix: 'm.', owner_id: '330406276972412928', guild_id: '525219058950109'}

I searched some methods of JSON object manipulation with Javascript but none of them fit in my need.

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

0

You can use Object.fromEntries and transform the objects into [key, value] tuples.

const data = [
  { key: 'PREFIX', value: 'm.' },
  { key: 'OWNER_ID', value: '14901414891498' },
  { key: 'GUILD_ID', value: '525219058950109' }
]

const newData = Object.fromEntries(data.map(({ key, value }) => 
  [key.toLowerCase(), value]))

console.log(newData)

about 4 years ago · Juan Pablo Isaza Denunciar

0

Using Array#reduce:

const data = [ { key: 'PREFIX', value: 'm.' }, { key: 'OWNER_ID', value: '14901414891498' }, { key: 'GUILD_ID', value: '525219058950109' } ];

const obj = data.reduce((acc, {key, value}) => ({
  ...acc, [key.toLowerCase()]: value
}), {});

console.log(obj);

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