Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

105
Vistas
How can I loop list an array containing object by starting from 1 to the last instead of starting from zero Javascript
const array=[
{
    "firstname":"akira",
    "lastname":"laine",
    "number":"090897878",
    "like":["pizza","coding","points","brownie"]
},{
    "firstname":"harry",
    "lastname":"pooter",
    "number":"070896778",
    "like":["Hogwarts","magic","Hagrid"]
},{
    "firstname":"sherlock",
    "lastname":"Holmes",
    "number":"080896975",
    "like":["Intriguing","case","Voilin"]
},{
    "firstname":"Kristian",
    "lastname":"Vos",
    "number":"080894575",
    "like":["Javascript","Gaming","Foxes"]
}  

]

I used recursive function to perform the task but no result yet

    function names(array,end) {
  if(array.length>end){
    console.log(array)
    return names(array-1,end)    
  }
    

} names(array,1)

i am stock with this for days now. I need help on this. You when you loop through the array containing object it list out the element in the array starting from zero to the last element in the array. My problem now is that how can loop through it starting from 1 to the last element in the array instead of zero.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

for (let i=1; i<array.length + 1; i++) { 
   console.log(array[i-1], i)   
}

This was able to solve the problem for me. Thanks everyone

about 4 years ago · Juan Pablo Isaza Denunciar

0

As Daniel says:

    // entire list starting a '0'
    for (let i=0; i<array.length; i++) { console.log(JSON.stringify(array[i])) }
    console.log();
    // entire list starting a '1'
    for (let i=1; i<array.length; i++) { console.log(JSON.stringify(array[i])) }

Or as an alternative:

    var newArray = [...array];
    newArray.shift();
    console.log();
    for (let i=0; i<newArray.length; i++) { console.log(JSON.stringify(newArray[i])) }

If you only wanted the lastname and likes of that entry:

    console.log();
    for (let i=1; i<array.length; i++) { 
      console.log(`${array[i].lastname} likes: ${array[i].like}`);
    }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda