Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!