Get all children from parent child JSON data
<p>I have parent-child JSON data and I want get all children (nested children) from selected parent.</p>

<p>For example, I have JSON data :</p>

<pre><code>[{
  "id": 1,
  "parent": 0,
  "name": "Parent"
}, {
  "id": 2,
  "parent": 1,
  "name": "Child 1"
}, {
  "id": 3,
  "parent": 2,
  "name": "Grand Child 1"
}, {
  "id": 4,
  "parent": 2,
  "name": "Grand Child 2"
}, {
  "id": 5,
  "parent": 1,
  "name": "Child 2"
}]
</code></pre>

<p>And I have function findAllChildren(1), where "1" is "parent" and then result of function should be :</p>

<pre><code>[{
  "id": 2,
  "parent": 1,
  "name": "Child 1"
}, {
  "id": 3,
  "parent": 2,
  "name": "Grand Child 1"
}, {
  "id": 4,
  "parent": 2,
  "name": "Grand Child 2"
}, {
  "id": 5,
  "parent": 1,
  "name": "Child 2"
}]
</code></pre>

<p>And in other case, if i call findAllChildren(2), result of the function should like below :</p>

<pre><code>[{
  "id": 3,
  "parent": 2,
  "name": "Grand Child 1"
}, {
  "id": 4,
  "parent": 2,
  "name": "Grand Child 2"
}]
</code></pre>

<p>What is the proper way to create function to solve that case? Thank you.</p>