I have an array and I want to simply push the item whenever a button clicked. But what happens is that the most recent pushed data overwrites the previous data of the array, I saw this when I am printing it. My primary requirements for the code is to implement the data structure of array while using objects/functions, thanks in advance for your help.
let BookInfo = [];
//create a storage for the book information
let Book =
{
Name: ' ' ,
Author: ' ' ,
Page: ' ',
addItem : function()
{
Name = document.getElementById('bTitle').value;
Author = document.getElementById('bAuthor').value;
Page = document.getElementById('bPages').value;
this.Name = Name;
this.Author = Author;
this.Page = Page;
BookInfo.push(Book);
document.getElementById('showArr').innerHTML = JSON.stringify(BookInfo);
}
};