array called 'notes' contains 5 objects , each object has keys
var notes = [
{
title: "Home",
message: "is a good story",
status: 'new',
author:"dala",
},
{
title: "School",
message: "Have to go everday",
status: 'new',
author:"aisha",
},
{
title: "study",
message: "we have exam to pass",
status: 'new',
author:"Omar",
},
{
title: "Work",
message: "dead line is close",
status: 'new',
author:"Said",
},
{
title: "homework",
message: "as today we need to do it",
status: 'new',
author:"Amal",
},
];
i want to update all the notes's status to be 'completed', the error is the code only update the first Object
function map(notes,callback){
const newNotes =[];
for(var i=0; i<notes.length; i++) {
const result = callback(notes[i].status = "completed",i);
newNotes.push(result);
return newNotes;
}
}
var outp = map(notes,function(value, i){
console.log(i)
for(var a= 0; a<value.length; a++){
return notes;
}
})
console.log(outp);
I was training on the callback function, and this training code was the face of a problem writing the code If you have useful resources to learn from, please share them with me
notes[i].status = "completed"in your callback argument.