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

165
Vistas
Converting an arrays to an object without keys

I am looking for a way to i convert this.

    const data = [{
                id: 1,
                fullnames: 'JosephSam',
                weight: 1231,
                currentdate: '2021-09-22'
    }]

into this

        const data = {
                id: 1,
                fullnames: 'JosephSam',
                weight: 1231,
                currentdate: '2021-09-22'
    }
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

const arr = [{
            id: 1,
            fullnames: 'JosephSam',
            weight: 1231,
            currentdate: '2021-09-22'
}];

const data = arr[0];

console.log(data.fullnames); // 'JosephSam'

This would be what you need. I do get the feeling this is isn't what you're looking for. If so, please give us a more complex example to see what it is you're dealing with.

about 4 years ago · Juan Pablo Isaza Denunciar

0

If you have multiple values inside your array, then you can have a separate object to insert each array value into it by having id as the object key.

Take a look at the following example.

const data = [
  {
    id: 1,
    fullnames: "JosephSam",
    weight: 1231,
    currentdate: "2021-09-22",
  },
  {
    id: 2,
    fullnames: "Jane",
    weight: 1431,
    currentdate: "2021-09-22",
  },
];

const mappedData = {};

data.forEach((element) => (mappedData[element.id] = element));

console.log("Mapped Data: ", mappedData);

Console log

Mapped Data:  {
  '1': {
    id: 1,
    fullnames: 'JosephSam',
    weight: 1231,
    currentdate: '2021-09-22'
  },
  '2': { id: 2, fullnames: 'Jane', weight: 1431, currentdate: '2021-09-22' }
}

Then you can refer each element by id as follows. (x is the id you need to get)

mappedData[x]
about 4 years ago · Juan Pablo Isaza Denunciar

0

I'm not sure what are you trying to do. But If you have a single indexed array you should to this:

var data = [{
    id: 1,
    fullnames: 'JosephSam',
    weight: 1231,
    currentdate: '2021-09-22'
}]
data = data[0];
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