Hi I am having a problem with my code hope somebody can help me with it.
I have a HTML file with two textboxes with id:name and another one with id:lname, and a submit button. When I press the button it executes this (function add) which is in a separate file.
var person = {}, people = [];
function add(){
person.name = document.getElementById('name').value;
person.lastname = document.getElementById('lname').value;
people.push(person);
console.table(people);
}
It seems to work fine the first time (It saves the values into the object and then into the array) but when I change the textboxes and press the button again, instead of saving the new values into the next position in the array it rewrites both positions with this new input duplicated
add(), start withperson = {}. Or better yet, use a local variable instead of a global one.