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

127
Views
añadir corchete en cada dos objetos

necesito agregar corchetes en cada dos objetos para que esta entrada de db foreach

 var Categories = [ { "text": "Mobile Recharge", "callback_data": 1 }, { "text": "Internet", "callback_data": 2 }, { "text": "Digital Code", "callback_data": 3 }, { "text": "Tv", "callback_data": 4 } ];

y esta es la salida que necesito, si hay 5 objetos, el último estará solo dentro del paréntesis y así sucesivamente.

 var Categories = [ [ { "text": "Mobile Recharge", "callback_data": 1 },{ "text": "Internet", "callback_data": 2 } ], [ { "text": "Digital Code", "callback_data": 3 },{ "text": "Tv", "callback_data": 4 } ], ];

este es el codigo completo

 let Categories = []; bot.hears('🛒 Categories', ctx => { db.query(`SELECT * FROM cat WHERE status = 1`, function(error, res) { res.forEach(function(row) { var cat = { text: row.title , callback_data: row.id } Categories.push(cat); }); var InlineKeyboardMarkup = { 'inline_keyboard': [Categories] } ctx.reply("Select a Category : \r", { "reply_markup": JSON.stringify(InlineKeyboardMarkup) }); Categories = [] }) })
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Esto debería hacerlo: un simple bucle for( ... )

 var Categories = [ { "text": "Mobile Recharge", "callback_data": 1 }, { "text": "Internet", "callback_data": 2 }, { "text": "Digital Code", "callback_data": 3 }, { "text": "Tv", "callback_data": 4 }, { "text": "something else", "callback_data": 5 } ]; const res=[]; for (let i=0;i<Categories.length; i+=2) res.push(Categories.slice(i,i+2)) console.log(res)

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