Javascript Array Foreach Callback Function With Recursion Push Values

I’ve been following this awesome solution. However for some reason on this block of code:

nodes.forEach(function(e){
    if(e.parent === currentNodeId){
        e = addChildrenToNode(e);
        node.children.push(e);
    }
});

The forEach callback function “e” param results to null instead of pushing the whole object into the node.children array. In order for me to get the actual values, I’ve manually set the values instead of using the “e” which will be the whole object e.g.:

node.children.push({ _id: e._id, name: e.name });

However, I’m not able to convert this line:

e = addChildrenToNode(e);

To do the recursion and append the children. I’m thinking that this is due to the old version of JS that we’re using on the server without the ES6 functionalities? Need your inputs. Thank you very much!