when i run this code it gives me error Cannot read properties of undefined (reading ‘id’) what’s the problem in my code?
tasklist=[{"id": 58,"taskName": "task-1","lists": []}]
const createItem = () => {
const itemName = document.getElementById("itemName").value;
const taskId = document.getElementById("task-id").value;
let itemObj;
tasklist.filter((object) => {
if (object.id === taskId) {
console.log("true");
itemObj = {
id: Math.floor(Math.random() * 100),
itemName: itemName,
done: false,
};
object.lists.push(itemObj);
}
return object;
});
displayItem(taskId, itemObj.id);
};