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

128
Visualizações
I made a list in JavaScript, and try to put it on the webpage but it only comes up [object object] [object object]

I want to make a list of books in JavaScript, and first I made the code so it would print out in the console window, but now I want to have the list in web page, because via a DOM-event (button) I want the user to be able to put in another book in the list. With certain criterias. But now as I try to put it in web I only get object object] [object object], and since I'm a noob I don't understand how to merge so the list I made with JavaScript is shown in the webpage? Sorry if this is confusing.

var array = [{
  "Title": "Machine Learning",
  "Year": 2020,
  "Price": 500
}, {
  "Title": "Artificial Intelligence",
  "Year": 2020,
  "Price": 1100
}, {
  "Title": "Algorithms and Data Structure",
  "Year": 1995,
  "Price": 400
}, {
  "Title": "Programming in C++",
  "Year": 1999,
  "Price": 200
}, {
  "Title": "Database Systems",
  "Year": 2020,
  "Price": 500
}];

document.getElementById("test").innerHTML = array

for (var i = 0; i < array.length; i++) {
  console.log(array[i])
}
<h1>Velkommen til mitt arbeidskrav i emnet:
</h1>

<h1>Intro til programmering! </h1>

<div id="test">
</div>

<input id="NewBook" placeholder="Enter book"></input>
<button id="btnNewBook">Click to add book</button>

<p> My book list:
  <ul id="MyBookList">
  </ul>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

What you're trying to show in the webpage is just an array (Object). You should loop over that array and show the title of the item, not the item.

const el = document.getElementById("test");

for (var i = 0; i < array.length; i++) {
    el.innerHTML += `<div>${array[i].Title}</div>`;
}

Also a tip: instead of rebuilding the dom with innerHTML you might think to use appendChild or insertAdjacentHTML functions.

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