Looping over an array, last value is displayed as undefined in html

This is the function in question. When I call the function, it displays a card for the last index in the array, but all text is undefined.

function appendBookLibrary() {

    let bookNameInput = document.getElementById("bookName");
    let authorInput = document.getElementById("authorName");
    let pageCountInput = document.getElementById("bookPages");

    let newBook = new Book(
        title = bookNameInput.value,
        author = authorInput.value,
        pages = pageCountInput.value,
        read = false

    myLibrary = [myLibrary + newBook];

const addButton = document.getElementById("addBookButton");
addButton.addEventListener("click", function() {

Read more here: https://stackoverflow.com/questions/68492404/looping-over-an-array-last-value-is-displayed-as-undefined-in-html

Content Attribution

This content was originally published by Surge at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: