I need to go through a list of objects to find the element and add a new element to the root, I can scroll through the list and find the element, but I can not add to the correct level
var data = [
    {
        "id": 1
    },
    {
        "id": 2
    },
    {
        "id": 3
    },
    {
        "id": 4,
        "children": [
            {
                "id": 6
            },
            {
                "id": 7                    
            }
        ]
    },
    {
        "id": 5
    }
];
function findById(data, id, element) {
    function iter(a) {
        if (a.id === id) {
            a.push(element); // ERROR
            result = a;
            return true;
        }
        return Array.isArray(a.children) && a.children.some(iter);
    }
    var result;
    data.some(iter);
    return result
}
var element = {
    "children": [{"id": 6}]
};
findById(data, 5, element);
document.write('<pre>' + JSON.stringify(data, 0, 4) + '</pre>');
 
     
     
    