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

174
Views
¿Obtener y formatear datos en matrices de objetos? Mecanografiado

Estoy tratando de devolver datos en una variedad de objetos... He hecho esto antes con JS, pero fue un desastre, estaba buscando un enfoque más limpio y aprendiendo lentamente TS pero parece que me he topado con una pared... .

 export {}; const cheerio = require("cheerio"); const fetch = require("isomorphic-fetch"); interface PlayerStats { name: string; role: string; score: string; matches: string; totalBattles: number; } const fetchData = async (faction: string) => { const req = await fetch("https://localhost/3000/" + faction); const data: string = await req.text(); const $ = cheerio.load(data); const SquadElements: Element[] = $("#teamDetails > div.memberList").toArray(); const playerStats: PlayerStats[] = SquadElements.map((el: Element) => { const name: string = $(el).find(".member .name p").text() || ""; const score: string = $(el).find(".member .stats .battlesWon").text(); const matches: string = $(el).find(".member .stats .matchesPlayed").text(); const role: string = $(el).find(".member .specialty h6").text(); const totalBattles: number = parseInt(matches) * 3; return { name, score, matches, role, totalBattles }; }); console.log(playerStats[0]); return playerStats; }; fetchData("9a7059e278");

console.log(playerStats[0]); devuelve name: 'name1name2name3name4name5'.. etc

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Gracias @Thomas por la ayuda... Fue tan simple como:

$("#teamDetails > div.memberList > .member").toArray();

en vez de:

$("#teamDetails > div.memberList").toArray();

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!