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

179
Vistas
How to get object property list data

I have a list of objects. Every object has a property which is a list of elements:

  { name       : 'Club 01'
  , id         : 1
  , form       : 45
  , points     : 0
  , tactics    : 'neutral'
  , played     : 0
  , gameset    : 0
  , playedWith : [ 8, 1, 2, 3 ] 
  } 

I want to go through the list and console log all existing elements:

for (let a = 0; a<clubs.width; a++) {
  for (let b = 0; b<clubs[a].playedWith.width; b++) {
    console.log(clubs[a].playedWith[b]);
  }
}

when i do it for one item, this works. however when i do it with a loop as aboce, this brings me to

undefined

Whats wrong with my code? How do i console log all items within playedWith property?

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

0

Elikill58 is right. Arrays have length property, not width property.

So your code would work well this way:

for (let a = 0; a < clubs.length; a++){
  for (let b = 0; b < clubs[a].playedWith.length; b++){
    console.log(clubs[a].playedWith[b]);
  }
}

Also, if you want to iterate through all items in the array, just for the sake of simplicity, you can write it like so:

for (const club of clubs) {
  for (const width of club.playedWith) {
    console.log(width);
  }
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

let b = { name: 'Club 01', id: 1, form: 45, points: 0, tactics: 'neutral', played: 0, gameset: 0, playedWith: [8, 1, 2, 3],

move: function() {
    return `
    ${ this.name }and
    ${this.id }and
    ${ this.form }and
    ${ this.points }and
    ${ this.tactics }and
    ${ this.played }and
    ${ this.gameset }and
    ${ this.playedWith }`
}

};

console.log(b.move()) for (var w in b) { console.log(${w}:${b.move()}) }

about 4 years ago · Juan Pablo Isaza Denunciar

0

You have to use length instead of width for both loop.

Here is an example :

 var clubs = [
 { name       : 'Club 01'
  , id         : 1
  , form       : 45
  , points     : 0
  , tactics    : 'neutral'
  , played     : 0
  , gameset    : 0
  , playedWith : [ 8, 1, 2, 3 ] 
  } 
];

for (let a = 0; a < clubs.length; a++) {
  for (let b = 0; b < clubs[a].playedWith.length; b++) {
    console.log(clubs[a].playedWith[b]);
  }
}

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