Array of objects: return only objects (and children) where attribute matches
<p>I have an array with several "levels" or children. I would like to create a new array of objects where archived===false so that no archived objects are listed.</p>

<p>So this...</p>

<pre><code>var arr = [
    {"id":1, "archived":false,"children":[
        {"id":1,"archived":true, "subs":[
            {"id":1,"archived":true},
            {"id":2,"archived":true},
            {"id":3,"archived":true}
        ]},
        {"id":2,"archived":false, "subs":[
            {"id":1,"archived":false},
            {"id":2,"archived":false},
            {"id":3,"archived":true}
        ]}
    ]},
    {"id":2, "archived":true,"children":[
        {"id":1,"archived":true, "subs":[
            {"id":1,"archived":true},
            {"id":2,"archived":true},
            {"id":3,"archived":true}
        ]},
        {"id":2,"archived":true, "subs":[
            {"id":1,"archived":true},
            {"id":2,"archived":true},
            {"id":3,"archived":true}
        ]}
    ]},
    {"id":3, "archived":false,"children":[
        {"id":1,"archived":false, "subs":[
            {"id":1,"archived":true},
            {"id":2,"archived":false},
            {"id":3,"archived":true}
        ]},
        {"id":2,"archived":false, "subs":[
            {"id":1,"archived":false},
            {"id":2,"archived":false},
            {"id":3,"archived":false}
        ]}
    ]}
];
</code></pre>

<p>Becomes...</p>

<pre><code>var arr = [
    {"id":1, "archived":false,"children":[
        {"id":2,"archived":false, "subs":[
            {"id":1,"archived":false},
            {"id":2,"archived":false}
        ]}
    ]},
    {"id":3, "archived":false,"children":[
        {"id":1,"archived":false, "subs":[
            {"id":2,"archived":false}
        ]},
        {"id":2,"archived":false, "subs":[
            {"id":1,"archived":false},
            {"id":2,"archived":false},
            {"id":3,"archived":false}
        ]}
    ]}
];
</code></pre>

<p>I've tried combinations of map, reduce, filter, and grep...but I probably do not have the order right, etc. I know I could just loop through each level, but I can't get it just right.</p>

<p>It would be great to have this contained in a linq.js enumerable array or in jQuery.</p>

<p><a href="https://jsfiddle.net/ksumarine/8fuj4077/1/" rel="nofollow">Non-working Example fiddle</a></p>