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

273
Views
¿Manera simple de enumerar una lista en javascript con índice?

En python hay un buen atajo para obtener el índice y el elemento de un interable:

 >>> arr=['a','b','c'] >>> for idx, arr in enumerate(arr): ... print (idx, arr) ... (0, 'a') (1, 'b') (2, 'c')

¿Sería lo siguiente en javascript, o tendría que ser una función de generador en su lugar?

 function enumerate1(arr) { let out = []; for (let idx=0; idx<arr.length; idx++) { let elem = arr[idx]; out.push([idx, elem]); } return out; } let arr1 = ['a','b','c']; for (let [idx, elem] of enumerate1(arr1)) { console.log(idx, elem); } // or, a bit more concise let arr2 = ['a','b','c']; const enumerate2 = (arr) => arr.map((idx, elem) => [idx, elem]); for (let [idx, elem] of enumerate2(arr2)) { console.log(idx, elem); }

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