title: Move item anywhere in a nested array
body: <p>I've managed to copy the intended object into the intended location (my code is below), but how do I <em>move</em> it? So it will not exist in the original location any more.</p>
  
  <p>So in my example, I want to take the object with id of <code>14</code> (very bottom of the object) and move it into the <code>children</code> of the object with id of <code>3</code> (towards the top).</p>
  
  <p>I know I need to modify this line: <code>item.children.push(itemToMove)</code> in my <code>moveItem</code> function, but some reason I can't think of it.</p>
  
  <p>Also sorry about the very big/nested object, I wanted to make sure to cover a deeply nested object.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const myObj = [
    {
      id: 1,
      name: '1',
      children: [
        {
          id: 2,
          name: '2',
          children: [
            {
              id: 3,
              name: '3',
              children: []
            }
          ]
        },
        {
          id: 4,
          name: '4',
          children: [
            {
              id: 5,
              name: '5',
              children: [
                {
                  id: 6,
                  name: '6',
                  children: [
                    {
                      id: 7,
                      name: '7',
                      children: []
                    }
                  ]
                }
              ]
            }
          ]
        },
      ]
    },
      {
      id: 8,
      name: '8',
      children: [
        {
          id: 9,
          name: '9',
          children: [
            {
              id: 10,
              name: '10',
              children: []
            }
          ]
        },
        {
          id: 11,
          name: '11',
          children: [
            {
              id: 12,
              name: '12',
              children: [
                {
                  id: 13,
                  name: '13',
                  children: [
                    {
                      id: 14,
                      name: '14',
                      children: []
                    }
                  ]
                }
              ]
            }
          ]
        },
      ]
    }
  ]
  
  let itemToMove = {
    id: 14,
    name: '14',
    children: []
  }
  
  // move item, return updated obj
  function moveItem(itemToMove, obj, parentId) {
  
    for (let i=0;i&lt;obj.length;i++) {
      const value = obj[i];
      const item = search(obj[i], parentId);
      if (item) {
        item.children.push(itemToMove); // pushed into children, but need to move not duplicate in
        break;
      }
    }
  
    function search(obj, id) {
      if (obj.id === id) {
        return obj;
      }
  
      for (let i=0;i&lt;obj.children.length;i++) {
        const possibleResult = search(obj.children[i], id);
          if (possibleResult) {
            return possibleResult;
          }
      }
    }
  
    return obj;
  };
  
  console.log(moveItem(itemToMove, myObj, 3))</code></pre>
  </div>
  </div>
  </p>