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

109
Views
cómo construir un objeto [clave, valor] use la cadena obtuvo la página del formulario

Quiero obtener dos elementos de la página y ponerlos en un objeto.

 const entryElements = await page.$$('div.kpi-entry'); const contents = await Promise.all( entryElements.map(async (element) => { const objValue= await (await element.$('span.text-xl'))?.innerText(); const objKey= await (await element.$('eui-base-v0-tooltip'))?.innerText(); const kpiObject = {objValue,objKey,}; return obj; })

);

obj devuelve

 { objValue: '1', objKey: 'A' }, { objValue: '2', objKey: 'B' }, { objValue: '3', objKey: 'C' }, { objValue: '4', objKey: 'D' }, { objValue: '5', objKey: 'E' }

pero esperaba

 { A: '1', B: '2', C: '3', D: '4', E: '5', }

cual es la mejor manera de hacer esto

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

0

Solo adapté su propio código, debe consultar MDN Working with Objects para obtener más detalles.

 const entryElements = await page.$$('div.kpi-entry'); const newObject = {}; const contents = await Promise.all( entryElements.forEach(async (element) => { const objValue= await (await element.$('span.text-xl'))?.innerText(); const objKey= await (await element.$('eui-base-v0-tooltip'))?.innerText(); newObject[objKey] = objValue; }) console.log(newObject)
about 4 years ago · Juan Pablo Isaza Report

0

 let obj = [ { objValue: "1", objKey: "A" }, { objValue: "2", objKey: "B" }, { objValue: "3", objKey: "C" }, { objValue: "4", objKey: "E" }, { objValue: "5", objKey: "F" }, ]; let map = obj.map(element => { return { [element.objKey]: element.objValue }; }); console.log(Object.assign(...map));

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!