Querying JavaScript Parent Child object
<p>I have a json object that shows parent children relationships.</p>

<p>I find it very difficult to query for a certain child.</p>

<p>For example here's the data.</p>

<pre><code>var parents =  [
    {
        name: 'Susan',
        children: [{
            name: 'Joe'
        }, {
            name: 'Sam'
        }, {
            name: 'Michael'
        }]
    }, 
    {
        name: 'Ted',
        children: [{
            name: 'Richard'
        }, {
            name: 'Brad'
        }]
    }
    ]
</code></pre>

<p>In an elegant way I'd like to be able to find the object based on parent name and child name.</p>

<p>Parent: Susan
Child: Joe</p>

<p>Here's how I'd do the 3 types of queries I'm trying to do in C#</p>

<pre><code>var parentQuery = parents.filter(parent=&gt; parent.name == 'Susan');
var childQuery = parents.filter(parent=&gt; parent.children.name == 'Joe');
var parentChildQuery = parents.filter(parent=&gt; parent.name == 'Susan' &amp;&amp; parent.children.name == 'Joe')
</code></pre>

<p>The parentQuery works out of the box in Javascript  to my delight. But the childQuery search doesn't work. Since parent has an internal array I'm not sure how to reference to query on a property. Shown below.</p>

<blockquote>
  <p>parent.children.name == 'Joe'</p>
</blockquote>

<p>Any help would be greatly appreciated!</p>