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 loop through an array of objects and see if values are empty

I'm failing to understand a concept which involves looping through an array of objects. Also, we're working with Google Tag Manager, therefore we still need to use the ES5 annotation.

My case:

We have a product array that contains multiple objects that contain very specific product data (e.g. product id, price, name etc.). It happens that some of these values are missing (e.g. undefined, null or ''). We are trying to create a rule that returns true whenever one of these values is missing and false if all are present.

I've been trying the following:

function getEmptyEcomValues () {

  var ecomDatalayer = {{ecommerce}} //the source of our array. This works so far. (see code below)

  var productArray = ecommerceEvent.products || [];

  // the problem is in this for loop. I can access the array but not all the keys and their values.

  for (var item in productArray) {
        if (productArray[item] == null || productArray[item] == undefined || productArray[item] == "") {
            return true;
      } else {
            return false;
      }

    //checkProperties(productArray) 
  
}
}

This script checks the array but keeps returning false. Even when key values are empty.

// if an array looks like this, it should return false. All values are present.

[
  {
    name: "Product1",
    id: "1234",
    price: "10.00",
    category: "video games"
  },
  {
    name: "Product2",
    id: "5678",
    price: "15.00",
    category: "video games"
  }
]

// if an array looks like this, it should return true. It has empty values.

[
  {
    name: "", //empty
    id: "1234",
    price: "10.00",
    category: "video games"
  },
  {
    name: "Product2",
    id: "5678",
    price: undefined, //undefined value
    category: "video games"
  }
]

Am I on the right track here?

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