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

176
Views
Empujando a una matriz con múltiples valores usando el nodo js - discord js

Así que tengo una matriz vacía:

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

Los datos que quiero recibir quiero que se vean así:

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

Lo que estoy recibiendo:

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

Básicamente, quiero obtener 1 título único con todos los valores debajo, y luego ir al siguiente título y obtener todos los valores allí.

Los datos en la base de datos se ven así:

 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

Actualmente, estoy enviando algunos valores a esta matriz a través de un bucle for de datos en una base de datos usando secuencialización, ofc eso no me está llevando a donde quiero llegar, pero... Espero que algunos puedan ayudarme en mi camino

 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

Creo que esto es lo que estás buscando:

 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}`; }); }

Tenga en cuenta que realizar la solicitud de base de datos ( logs_table.findAll ) dos veces es probablemente un error, debería poder recuperar todos los datos en una sola solicitud.

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!