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

279
Vistas
alasql & grouping functions: use Javascript or AlaSQL to create the resulting object?

Below the input data:

[
        {
            "name": "jim",
            "color": "blue",
            "age": "22"
        },
        {
            "name": "Sam",
            "color": "blue",
            "age": "33"
        },
        {
            "name": "eddie",
            "color": "green",
            "age": "77"
        }
]

I would like a resulting object using a single AlaSQL query:

{
        "jim": {
            "color": "blue",
            "age": "22"
        },
        "sam": {
            "color": "blue",
            "age": "33"
        },
        "eddie": {
            "color": "green",
            "age": "77"
        }
}

Is there any way to achieve it one shot with a AlaSQL query ? This would allow to easily find contact info (e.g. data["eddie"].age)

The closest way I found is this:

var res = alasql('SELECT name, ARRAY(_) AS details FROM ? GROUP BY name', [data]);

but I still obtain an array under this format:

[
    {
        "name": "jim",
        "details": [{
            "color": "blue",
            "age": "22"
        }],
    },
    {
        "name": "Sam",
        "details": [{
            "color": "blue",
            "age": "33"
        }],
    },
    {
        "name": "eddie",
        "details": [{
            "color": "green",
            "age": "77"
        }]
    }
]

What would be the fatest and efficient way to achieve the goal ?

about 4 years ago · Juan Pablo Isaza
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