When I use consolelog on my array there are 2 duplicates of it, ones empty and ones with the objects that get pushed, when I refresh the page (I use localStorage to save the array) the array has an exact copy. Here’s the code:
let projectArray = [];
const saveProjectArray = JSON.parse(localStorage.getItem("projectList"));
projectArray = saveProjectArray;
allTask.addEventListener('click', (e) => {
saveProjectArray.forEach(element => {
console.log(`Name: ${element.name}`);
});
});
function Project(name, id){
this.name = name;
this.id = id;
}
function makeProject(projectName){
const newProjectObj = new Project(projectName, getId);
//Code
projectArray.push(newProjectObj);
localStorage.setItem('projectList', JSON.stringify(projectArray));
}
I’ve tried deleting the localstorage lines but still the issue persists.