I am a beginner in javascript and I'm trying to figure out how to remove all objects with the completed property set to true.
However, my current function is not achieving this. Can anyone help identify what I may be missing?
const tasks = [{
title: 'task1',
completed: true
},{
title: 'task2',
completed: true
},{
title: 'task3',
completed: true
},{
title: 'task4',
completed: true
}]
const removeCompletedTasks = function(tasks){
tasks.forEach(function(task,index){
if(task.completed){
tasks.splice(index,1)
}
})
}
removeCompletedTasks(tasks)
console.log(tasks)