title: JavaScript -- split off one branch of a hierarchical array or JSON object
body: <p>I have a JSON object that is a nested array that is of the following form:  </p>
  
  <pre><code>{
      "name": "Math",
      "children": [
          {
              "name": "Trigonometry",
              "children": [
                  {
                      "name": "Right Triangles and an Introduction to Trigonometry",
                      "children": [
                          {
                              "name": "The Pythagorean Theorem",
                              "children": [
                                  {
                                      "name": "The Pythagorean Theorem",
                                      "size": 30
                                  },
                                  {
                                      "name": "Pythagorean Triples",
                                      "size": 52
                                  },
                                  {
                                      "name": "Converse of the Pythagorean Theorem",
                                      "size": 13
                                  }
                              ]
                          }
                      ]
                  }
              ]
          },
          {
              "name": "Algebra",
              "children": [
                  {
                      "name": "Equations and Functions",
                      "children": [
                          {
                              "name": "Variable Expressions",
                              "children": [
                                  {
                                      "name": "Evaluate Algebraic Expressions",
                                      "size": 26
                                  }
                              ]
                          }
                      ]
                  }
              ]
          }
      ]
  }
  </code></pre>
  
  <p>The full array is actually much larger and can be seen <a href="http://pastebin.com/MJvuBchQ" rel="nofollow">here</a>.  I'm using it to build interactive graphs and charts using D3.js (or perhaps other libraries).  Because it's so large, I'd like to be able to split the array by branch.  In other words, to carve out particular branches of the array.</p>
  
  <p>For instance, is there a way to just pull out the node "Trigonometry" and all its children?  Or "Algebra" and all its children?  Then "Trigonometry" or "Algebra" would become the new root or parent node.</p>