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

119
Views
Creando una nueva matriz de objetos con cada función.

Estoy construyendo un web scraper usando node/titiritero/cheerio

Usando esto, puedo consolar. registrar las cadenas correctas. Estoy luchando por entender si esto es posible.

 $('table[class="ad_tab"]') .find("tbody > tr > td") .each(function (index, element) { if ((index + 1) % 8 == 0) { console.log($(element).text()); console.log("Start New JSON"); } else { console.log($(element).text()); }

mi salida son las siguientes cadenas

 1 2 3 4 5 6 7 8 Start New JSON 9 10 11 12 13 14 15 16 Start New JSON

Mi resultado previsto es:

 [ { "A": "1", "B": "2", "C": "3", "D": "4", "E": "5", "F": "6", "G": "7" "H": "8" }, { "A": "9", "B": "10", "C": "11", "D": "12", "E": "13", "F": "14", "G": "15" "H": "16" } ]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede crear su caso en torno a esta solución: Básicamente, reemplace de each con reduce .

 let input = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]; // input = $('table[class="ad_tab"]').find("tbody > tr > td") let output = input.reduce((arr, value, i) => { let remainder = i % 8; if (!remainder) { arr.push({}) }; let obj = arr[arr.length - 1]; let char = String.fromCharCode(97 + remainder); obj[char] = value; return arr; }, []); console.log(output)

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!