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

89
Vistas
accessing objects in new array

const lineExampleOne = 
  [ { weight: 150, floor: 2 } 
  , { weight: 200, floor: 3 } 
  , { weight: 120, floor: 5 } 
  , { weight:  80, floor: 2 } 
  , { weight: 180, floor: 4 } 
  , { weight: 170, floor: 4 } 
  ];

let newArray = [];

lineExampleOne.forEach((person)=>{
  newArray.push(person);
})

console.log(newArray);

The console returns something like this [object Object],[object Object] etc...

How do I correctly add each object to my empty newArray?
How do I properly access each objects properties from my newArray?
and is there a way to test how many unique values I have for floors and weight of all the objects in my newArray ?

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

0

The console returns something like this [object Object],[object Object] etc...

That's just how the console logs objects. If you want more insight when logging collections like this I suggest using console.table(newArray).

How do I correctly add each object to my empty newArray?

Your code looks correct. Could be more succinct using map if interested (since map returns a new array). E.g. const newArray = lineExampleOne.map((a) => a);

How do I properly access each objects properties from my newArray?

You'll need to use find. E.g. const item = newArray.find(({ weight }) => weight === 200); console.log(item.weight). find will return the first match. If you want all matches then you'll want to use filter.

is there a way to test how many unique values I have for floors and weight of all the objects in my newArray.

Yes. Set will dedupe arrays, so you can use it for properties on a collection like so.

const distinctWeights = [...new Set(newArray.map((a) => a.weight))];
console.log(distinctWeights.length);
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