I am making a simple to do app and am stuck on updating the data array when a new task is added. Right now, if you add a new task, the entire array re-populates on the display and duplicate values are listed. How do I resolve this so that only one iteration of the array displays any time it is updated on the page?
const completedDivs = document.getElementById("completed");
const taskDivs = document.getElementById("tasks");
const addBtn = document.querySelector(".fa-plus");
const input = document.getElementById("newTask");
// SET UP DEFAULT TO DO TASKS
let todos = [
{ completed: false, task: "Make Coffee", id: 1 },
{ completed: false, task: "Walk the dog", id: 2 },
{ completed: true, task: "Make calculator app", id: 3 },
];
// SET UP REQUIRED VARIABLES
let taskNo = (completedDivsLength + taskDivsLength) + 1;
// MAP OUT DEFAULT TASKS TO DISPLAY
function generateToDo() {
todos.map(todo => {
// CREATE A NEW DIV
let newTask = document.createElement("div");
// GIVE THE DIV AN ID
newTask.id = `div${taskNo}`;
if(todo.completed) {
// FORMAT THE DIV
newTask.innerHTML = `<input type="checkbox" id="task${taskNo}" checked>
<label for="task${taskNo}">${todo.task}</label>
<i class="far fa-trash-alt" id="trash${taskNo}"></i>`
// Check the item off the list
newTask.classList.add("checked");
// Add the task to the completed list
completedDivs.appendChild(newTask);
} else if (!todo.completed) {
// FORMAT THE DIV
newTask.innerHTML = `<input type="checkbox" id="task${taskNo}">
<label for="task${taskNo}">${todo.task}</label>
<i class="far fa-trash-alt" id="trash${taskNo}"></i>`
// Uncheck the task from the list
newTask.classList.remove("checked");
// Move the task to the To Do list
taskDivs.appendChild(newTask);
}
// INCREMENT THE TASK NO BY 1
taskNo++;
});
}
// ADD NEW TASKS
addBtn.addEventListener("click", () => {
todos.push({ completed: false, task: `${input.value}`, id: taskNo });
generateToDo();
// RESET THE INPUT FIELD TO NOTHING
input.value = "";
});
// AUTOMATICALLY LOAD THE DEFAULT TO DOS
window.onload = generateToDo();
http://kamagraday.com/ kamagra reviews forum
provigil 100mg – buy provigil modafinil reviews
http://fildenahim.com fildena 100 for sale
https://wardenafil.com levitra bayer
accutane buy india – buy generic accutane online accutane online no rx
buy amoxicilin 500 mg canada – amoxicilina 500 mg buy amoxil
https://levitradd.com/ levitra 40 mg best price
vardenafil com – vardenafil generic levitra order vardenafil online pharmacy
http://otcmailmeds.com buy prescription drugs online without
http://levitradd.com/ levitra
ivermectin price – generic ivermectin for humans ivermectin 0.1 uk
tadalafil 20 mg soft tabs – internet pharmacy mexico buy cialis canada review
stromectol cream – ivermectin 90 mg
how do i get accutane – accutane from canada buy accutane mastercard
http://costpills.com 50 mg viagra price
http://prescriptionhim.com/ how to get generic viagra without perscriptions
900mg lyrica – ed drug india pharmacy
https://prescriptionhim.com/ viagra prescription template printable word
https://himshairloss.com/ can you buy propecia over the counter
amoxicillin for sale for humans 500 mg – generic amoxicillin cost generic amoxicillin 500mg
viagra San Antonio – blue pill for ed buy generic viagra online paypal
http://ivermectinovercounter.com ivermectin for humans for sale
where to buy tadalafil on line – buy generic cialis uk tadalafil canada generic over the counter
ivermectin 4 mg – buy ivermectin nz ivermectin buy australia
buy deltasone online – buy prednisone online from mexico online order prednisone
https://stromectolhumans.com/ ivermectin pills for humans
http://viagraxyu.com viagra levitra and cialis
provigil 100 mg – modafinil generic modafinil online
http://iwermectin.com/ ivermectin for humans for sale
zithromax cost – zithromax antibiotic generic zithromax 250mg
furosemide 80 mg coupon – furosemide price in usa lasix medication
generic clomid – order clomid 100mg clomid prescription
get a viagra prescription online – viagra for sale cheap how much is over the counter viagra
http://ivermectineffects.com/ ivermectin tablets amazon
https://ivermectinovercounter.com/ stromectol
http://ivermectineffects.com stromectol
how to get in health portal my cw 35 californial health insurance
stromectol 3mg tablets side effects https://ivermectinhome.com
http://ivermectinus.com/ ivermectin no prescription
http://zithrozpack.com/ cost of zithromax 500 mg
levitra substitute http://levitrair.com how long for levitra to work
harvard medical school, department of global health pectin health risks
where to buy legitamate ivermectin https://ivermectinhome.com
ivermectin http://stromectolus.com ivermrctin tablets
george bush sr health update what med with asthma can you not give to copd
ivermectin otc https://ivermectinhome.com
https://albuterolotc.com/ ventolin inhaler
why is there a deadline for health care reform the world health organization announced its first ever global strategy to deal with what?
fda ivermectin https://ivermectinhome.com
ivermectin https://stromectolus.com ivermectin kaufen
affordable health care coverage how do you get hiv
can humans take horse ivermectin https://ivermectinhome.com
ivermectin https://ivermcov.com/# ivermectin for humans where to buy
javascript-help.li and british pharmacies shipping to usa https://pharmvolk.com highest rated canadian pharmacies
how to get accurate test results for autoimmune arthritis https://ventolinhfaer.com/ combivent respimat
by 2000 how many americans have died from aids quizlet health department portage county ohio
ivermectin tablets for humans for sale https://ivermectinhome.com
javascript-help.li recommended ivermectin horse paste for humans https://ivermectini.com ivermectin tablets
imaging healthcare specialists san diego http://ivermectinhumans.com stromectol
how long after exercise to take blood pressure ivermectina posologia http://iveramectin.com ivermrctin tablets
javascript-help.li with stromectol https://ivermectiny.com stromectol
atlanticare ob gyn galloway nj what health insurance do they accept http://sansordonnancemd.com vardenafil biogaran 20 mg
javascript-help.li vs what is ivermectin http://ivermectiny.com ivermectin for humans
generic for viagra https://viagrob.com professional brand viagra info
javascript-help.li recommended ivermectin 6mg http://ivermectinhum.com stromectol how much it cost
ivermectina preГ§o ivermectin http://stromectl.com ivermectin price comparison
http://stromectolo.com – buy ivermectin online for humans
zithromax z pak https://azithrozpack.com z pack
arm cuff blood pressure monitor http://withoutscript.com – viagra for men
prescription strength zyrtec 20 mg – https://allergyd.com
ivermectin http://stromectolforte.com/ stromectol storbritannien stromectol 6mg
ivermectin 6 mg https://stromectolforte.com/ ivermectin ivermectin tablets for sale
ivermectin мЁлќјмќё 구매 http://www.ivermecton.com/ ivermectin
sti symptoms http://ivermcov.com – stromectol 3mg
ivermektin 1% grädde generisk http://www.stromectoloff.com/ ivermectin
viagra for women https://www.viagwdp.com/# buy viagra tablets viagra coupon walgreens
https://sildenafilhim.com erectile dysfunction and hypertensive heart disease
http://www.viawithoutdctrs.com – low price viagra
nitroglycerin and viagra https://viagwdp.com/ viagra boys sports buy viagra online with paypal in canada
prednisone 10mg pack – prednisone 10mg without prescription prednisone 40 mg
prednisone india – prednisone 5mg without prescription where can i buy prednisone over the counter
accutane 20mg capsules – isotretinoin medication accutane prescription discount
parx casino online – online gambling online casino no deposit bonus
ed pills for sale – buy ed medications best pills for ed
can you buy ivermectin in the us http://ivermectinol.com
xyncam http://otcstromectol.com/ ivermectin for humans for sale cvs
buy generic synthroid 150mcg – cost of viagra 100mg canadian cialis and healthcare
sildalis online – sildalis uk metformin 1000mg canada
buy acillin sale – purchase plaquenil online cheap plaquenil cost
buy hydroxychloroquine pills – order generic plaquenil oral hydroxychloroquine
cost cenforce 50mg – zyloprim 100mg us zovirax 800mg brand
order tetracycline 500mg – purchase flexeril pill citalopram online order
buy tadalafil 40mg sale – tadalafil women where can i buy stromectol
generic cialis online fast shipping where to get tadalafil
tadalafil dosage cialis without prescription
buy generic cialis online with mastercard tadalafil drug
side effects for tadalafil best price usa tadalafil
side effects for tadalafil https://cialiswbtc.com/
https://www.ivermectinoge.com/ stromectol 6 g
stromectol tablets 3 mg buy ivermectin 6mg
generic ivermectin 6 mg generic ivermectin 12 mg