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

195
Views
¿Cómo puedo pasar múltiples const de .entries en un bucle "for"?

tengo este codigo:

 for (const [index, value] of txtfile1.entries()) { console.log(`${index}: ${value}`); }

Y necesito pasar este bucle un archivo txt más para hacer algo como esto:

 for (const [index, value] of txtfile1.entries()) && (const [index2, value2] of txtfile2.entries()) { console.log(`${index}: ${value} and ${index2}: ${value2}`); }

Entonces, mi objetivo es usar datos de dos archivos txt diferentes en el mismo bucle. ¡Por favor ayuda!

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

0

no puede recorrer varias cosas directamente en un bucle for . Use un ciclo que proporcione índices, luego utilícelo para indexar en ambas matrices.

 const e1 = txtfile1.entries(); const e2 = txtfile2.entries(); e1.forEach(([key, value], index) => { const [key2, value2] = e2[index]; console.log(`${key}: ${value} and ${key2}: ${value2}`); });
about 4 years ago · Juan Pablo Isaza Report

0

Tal vez puedas tomar las entradas más largas y hacer un bucle como este

 const e1 = ["A1","A2","A3"] const e2 = ["B1","B2"]; const longest = e1.length > e2.length ? e1 : e2 for (const [index] of longest.entries()) { console.log(`${index}: ${e1[index] || ""} and ${index}: ${e2[index] || ""}`); }

producción:

 0: A1 and 0: B1 1: A2 and 1: B2 2: A3 and 2:
about 4 years ago · Juan Pablo Isaza Report

0

Así que tengo un comentario de Jupri : ¿no puedes simplemente usar anidado?

 for (const [index, value] of txtfile1.entries()) for (const [index2, value2] of txtfile2.entries()) {console.log(${index}: ${value} and ${index2}: ${value2})}

Y funcionó, muchas gracias a Jupri ya todos los que respondieron.

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!