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

171
Vistas
Pushing to to array with multiple values using node js - discord js

So I have an empty array:

        const logsEmbed = {
            color: '15c9c9',
            title: '',
            fields: [],
            timestamp: new Date()
        }

The data I want to receive I want to look something like:

{
  name: headline1,
  value: value1 \n value2 \n value3,
},
{
  name: headline2,
  value: value1 \n value2 \n value3,
}

What i am getting:

{
  name: headline1,
  value: value1,
},
{
  name: headline1,
  value: value2,
}

Basicly I want to get 1 unique headline with all the values under it, and then go to the next headline and get all the values there

The data in the database looks like:

1|Headline1|Value1|2022-04-22 18:05:52.473 +00:00|2022-04-22 18:05:52.473 +00:00
2|Headline1|Value2|2022-04-22 18:15:40.061 +00:00|2022-04-22 18:15:40.061 +00:00
3|Headline1|Value3|2022-04-22 18:16:45.313 +00:00|2022-04-22 18:16:45.313 +00:00
4|Headline2|Value4|2022-04-22 18:19:13.985 +00:00|2022-04-22 18:19:13.985 +00:00
5|Headline2|Value5|2022-04-22 18:19:36.230 +00:00|2022-04-22 18:19:36.230 +00:00

Currently This array I am pushing some values to through a for loop from data in a database using sequelize, ofc that is not getting me where I want to get but.. I hope some can help me on my way

const raids = await logs_table.findAll({ attributes: ['raid'], group: ['raid'] });
        for(const raid of raids)
        {
            const logs = await logs_table.findAll({ attributes: ['raid', 'link' ], where: {raid: raid.raid }});
            for(const log of logs)
            {
                logsEmbed.fields.push({name: log.raid, value: log.link, inline: false });
            }
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I think this is what you are looking for:

const raids = await logs_table.findAll({
  attributes: ['raid'],
  group: ['raid'],
});
for (const raid of raids) {
  const logs = await logs_table.findAll({
    attributes: ['raid', 'link'],
    where: { raid: raid.raid },
  });
  logs.forEach((log) => {
    const matchIndex = logsEmbed.fields.findIndex(
      (field) => field.name === log.raid
    );
    if (matchIndex < 0)
      logsEmbed.fields.push({ name: log.raid, value: log.link });
    else logsEmbed.fields[matchIndex].value += ` \n ${log.link}`;
  });
}

Note that performing the DB request (logs_table.findAll) twice is probably a mistake, you should be able to retrieve all the data in one single request.

about 4 years ago · Santiago Trujillo 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