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

133
Views
Quiero imprimir el índice de todos los elementos sin usar forEach o filter o map

Aquí está mi código, me está dando el mismo número de índice del elemento.

yo lo quiero 0,1,2,3,4,5,6

 let as=[1, 2, 3, 4, 5, 5,5] for(let i=0;i<as.length;i++){ console.log(as[i], as.indexOf(as[i])) }

Aquí está mi salida :

 1 0 2 1 3 2 4 3 5 4 5 4 5 4
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Si entiendo su pregunta correctamente, desea obtener el índice de los elementos disponibles en una matriz. Si es así, entonces puedes hacer esto :

 let as = [1, 2, 3, 4, 5, 5,5]; const indexArray = as.map((item, index) => index); console.log(indexArray.join(','));

about 4 years ago · Juan Pablo Isaza Report

0

Cree una matriz en la que pueda insertar los índices y luego cree una cadena con join .

 const as = [1, 2, 3, 4, 5, 5, 5]; let out = []; for (let i = 0; i < as.length; i++) { out.push(i); } console.log(out.join(','));

about 4 years ago · Juan Pablo Isaza Report

0

Prueba esto:

 let as=[1, 2, 3, 4, 5, 5,5] for(let i=0;i<as.length;i++){ console.log(as[i], as.indexOf(as[i],i)) }

Explicación: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf

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!