I have time slots like 9:00, 9:10, 9:20, etc. What I am trying to achieve is that when the person edits the task of that slot and clicks the button, then the task{} object is built with the timeDeclared and the info. then the task{} is added into an array if the array does not contain the timeDeclared already, if it does, it gets replaced by the new info. The goal of this is for me to then save the array into the memory that way when the page loads I can load the array from memory and place the tasks in the time slots they belong.
current outcome = it keeps getting replaced
wanted outcome = checks for existing time slot object in the array, add if it does not exist, replace if it does
$("li").on("click", "button", function () {
let wrap = $(this).parents("li");
let info = $(wrap).find("p").text().trim();
let timeDeclared = $(wrap).find(".slotMinutes").text().trim();
var task = {};
task.time = timeDeclared;
task.info = info;
var tasks = [];
add(tasks, timeDeclared)
function add(tasks, time) {
const found = tasks.some(el => el.time === timeDeclared);
if (!found) tasks.push({ task });
return tasks;
}
console.log(add(tasks));
tasks.push(task)
localStorage.setItem("data", JSON.stringify(tasks))
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>




