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

108
Visualizações
How to display values from array in JS?

I want to display all values from array categories, but I always got [object object] or undefined. Here is code in last lines if statement, there is that problem in part between bracket [] when I want to call categories and type of categories is Object:

  const urlKeys = [...new URL(window.location.href).searchParams.keys()];

  let categories = [];

  let count = urlKeys.length;

  for (let i = 0; i < count - 1; i++) {
    categories.push({ type: paramsFromUrl.get('category' + i) })
  }  //Here I push elements in categories

  if (urlKeys[0] === 'allCategories') {
    document.getElementById('notice').innerText = "All categories included: [" + categories + "]";
    return viewsjs.createRestaurantCards(filterjs.findRestaurantsByCategory(await restaurantsjs.loadRestaurantsJSON(), categories));
  } //Here is problem
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can’t concatenate an Array directly into a String; it’s simply not the way it works. Seems like you need join(), which would return another String that you can successfully concatenate into your broader string to write into the DOM:

document.getElementById('notice').innerText = "All categories included: [" + categories.join(", ") + "]";
about 4 years ago · Juan Pablo Isaza Relatório

0

categories is an array of objects. If you want to convert that to a string, you need to do JSON.stringify

"All categories included: " + JSON.stringify(categories);

If you only want to display the type and not the whole object, then:

"All categories included: [" + categories.map(obj => obj.type) + "]";
about 4 years ago · Juan Pablo Isaza 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