Change an array in a function

Well as it still not very clear what you want to do with your function, we can make arbitrary examples how things can be done.

//array of objects
let mod = [{"naam":"peter", "age":5 },{"naam": "jan", "age":5 },{"naam": "klaas", "age":5 },{"naam": "pieter", "age":5 },{"naam": "miep", "age":5}];

//name to search
let targetname = "jan"

//output does not exist yet cos we don't know can we find the name
let output = null

// lets modify the array by using .map method
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
mod = mod.map(obj => {
   // every object in array explored to find the target
    // if naam propert has value we are searching
   if(obj.naam === targetname){
       obj.age ++ //lets make that person one year older (change).
       output = obj // as we have success of, lets put that object to output variable 
   }
   return obj 
})

//lets write changed array to debug tab to see what just happened
node.warn('changed array: '+JSON.stringify(mod))

//as mod array is modified, you may wan to store it in context but that's another story
//context.set("mod",mod)

// send message if we have found person in array and made changes
if(output !== null){
    //send changed object
    msg.payload = output
    // or send whole modified arrray
    //msg.payload = mod
    return msg;
}