Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

170
Visualizações
Need to hide null from output for my products flex grid

I need to display products in various categories on my company's website, but sometimes a value will be null. I would like to display nothing for those situations but I have no idea how to go about doing that.

Any help would be appreciated.

I can't share the endpoint, accept, or authorization, thus the strange "goes here" text in the code:

var settings = {
  "url": " 'API endpoint goes here' ",
  "method": "GET",
  "timeout": 0,
  "headers": {
    "accept": " 'JSON goes here' ",
    "Authorization": " 'authorization key goes here' "
  },
};

$.ajax(settings).done(function(response) {
  console.log(response);

  $.each(response.data, function(index, value) {
    console.log(value);

    var name = value.name;
    var productNumber = value.productNumber;
    var size = value.size;
    var photo = value.primaryPhoto.standard;
    var id = value.id;

    $('.output').append('<div class="single-product"><div class="photo"><img src="' + photo + '" alt="product bag"/></div><h5 class="name">' + name + '</h5><p class="productNumber">' + productNumber + '</p><p class="size">' + size + '</p><a href="https://productpage.co/product-single/?id=' + id + '"><div class="button" style="text-align: center; font-weight: bold; color: white;">LEARN MORE</div></a></div>');
  })
});
almost 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

you can use return to skip to next iteration when value is null or if you wanted to break completely the loop you can use return false;

$.each(response.data, function(index, value) {
  console.log(value);

  //skip to next iteration/product when there's no data in value
  if (value == null) {
    return;
  }

  var name = value.name;
  var productNumber = value.productNumber;
  var size = value.size;
  var photo = value.primaryPhoto.standard;
  var id = value.id;

  $('.output').append('<div class="single-product"><div class="photo"><img src="' + photo + '" alt="product bag"/></div><h5 class="name">' + name + '</h5><p class="productNumber">' + productNumber + '</p><p class="size">' + size + '</p><a href="https://backyardboost.co/product-single/?id=' + id + '"><div class="button" style="text-align: center; font-weight: bold; color: white;">LEARN MORE</div></a></div>');
})
almost 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda