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

92
Vistas
trying to convert array of list to object?

i am trying to convert array key/value pair to an object using map and formEntries function i am getting an error message:'Object.fromEntries is not a function' any idea about the fix

main.js

  const data = {}
  const channelsMap = new Map(details.channels);
    const channels = Object.fromEntries(channelsMap);
  data = channels;

expected output

data : {
 channels: {
   "EM": true,
   "SMS": false
}
}

data

  { details: {
       "channels": [
          {
            "channelType": "EM",
            "isActive": "true"
          },
          {
            "channelType": "SMS",
            "isActive": "false"
          }]
    }
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You need to reduce the details.channels array into an object where the channelType is the key and the isActive is the value.

const original = {
  details: {
    channels: [
      { channelType: "EM"  , isActive: true  },
      { channelType: "SMS" , isActive: false },
    ]
  }
};

const transformed = {
  data: {
    channels: original.details.channels
      .reduce((acc, { channelType, isActive }) =>
        ({ ...acc, [channelType]: isActive }), {})
  }
};

console.log(transformed);
.as-console-wrapper { top: 0; max-height: 100% !important; }

about 4 years ago · Juan Pablo Isaza Denunciar

0

Upgrading your Node version to something above v12.0.0 should do it. This method isn't included in your current Node version. Documentation here.

about 4 years ago · Juan Pablo Isaza Denunciar

0

first is not allowed to use const when you want to change the value , second this is the code to expected output :

let data = {channels:details.channels.map(channel => ({[channel.channelType] : JSON.parse(channel.isActive) }))};

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