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

174
Vistas
JS For-Loop through objects' keys in an array

I have an array like this:

const list = [
    {
      quantity: 100,
      cost: 100,
      fee: 100,
    },
    {
      quantity: 200,
      cost: 200,
      fee: 200,
    },
    {
      quantity: 300,
      cost: 300,
      fee: 300,
    },
  ];

I would like to make a function that loops through it to get the total of each object's key like this:

  const cal = (item) => {
    let total = 0;
    for (let i = 0; i < list.length; i++) {
      total = list[i].item + total;
    }
    return total;
  };

So that I could run something like this:

console.log(cal(quantity));
console.log(cal(cost));
console.log(cal(fee));

Is the a way to achieve this please? I appreciate it!

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