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

118
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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