title: Breadth first traversal of object
body: <p>I am making a program that solves a puzzle game, and it finds all the possible moves on a board and puts all the possible resulting boards in an object. Then it finds all the possible moves for the resulting boards, and so on. The object will look something like this:</p>
  
  <pre><code>{
    "board": {
        "starts": [[0,0],[0,3]],
        "blocks": [[3,0],[3,3]],
        "ends":   [[2,4]]
    },
    "possibleMoves": [
      {
        "board": {
          "starts": [[0,0],[2,3]],
          "blocks": [[3,0],[3,3]],
          "ends":   [[2,4]]
        },
        "possibleMoves":[
          {
            "board": {},
            "possibleMoves": [{}]
          }
        ]
      },
      {
        "board": {
          "starts": [[0,3]],
          "blocks": [[3,0],[3,3]],
          "ends":   [[2,4]]
        },
        "possibleMoves":[{}]
      }]
  }
  </code></pre>
  
  <p>I can figure out how to add the possible moves from the top-level board, but I cannot figure out how to loop through all the resulting boards in the second level and figure out their possible moves, and then loop through all the third level boards and so on. How can I add the possible moves and traverse the object using a breadth-first search?</p>