title: how to search an array full of objects based on a key and return a specific object
body: <p>I have an array of objects as :</p>
  
  <pre><code>    [{
      "businessunit": [{
          "Area": [{
              "Asset": [{
                  "Wells": {
                      "Well": "Well 11"
                  },
                  "name": "Field 1"
              }, {
                  "Wells": {
                      "Well": "Well 12"
                  },
                  "name": "Field 2"
              }],
              "name": "Archer"
          }, {
              "Asset": [{
                  "Wells": {
                      "Well": "Well 13"
                  },
                  "name": "Field 3"
              }, {
                  "Wells": {
                      "Well": "Well 14"
                  },
                  "name": "Field 4"
              }],
              "name": "Anderson"
          }],
          "name": "North America"
      }, {
          "Area": [{
              "Asset": [{
                  "Wells": {
                      "Well": "Well 15"
                  },
                  "name": "Field 5"
              }, {
                  "Wells": {
                      "Well": "Well 16"
                  },
                  "name": "Field 6"
              }],
              "name": "ArcherSouth"
          }, {
              "Asset": [{
                  "Wells": {
                      "Well": "Well 17"
                  },
                  "name": "Field 7"
              }, {
                  "Wells": {
                      "Well": "Well 18"
                  },
                  "name": "Field 8"
              }],
              "name": "AndersonSouth"
          }],
          "name": "South America"
      }],
      "name": "XYZ Oil Co"
  }, {
      "businessunit": [{
          "Area": [{
              "Asset": {
                  "Wells": {
                      "Well": "Well 19"
                  },
                  "name": "Field 9"
              },
              "name": "Archer"
          }, {
              "Asset": [{
                  "Wells": {
                      "Well": "Well 110"
                  },
                  "name": "Field 10"
              }, {
                  "Wells": {
                      "Well": "Well 120"
                  },
                  "name": "Field 20"
              }],
              "name": "Anderson"
          }],
          "name": "North America"
      }, {
          "Area": {
              "Asset": [{
                  "Wells": {
                      "Well": "Well 130"
                  },
                  "name": "Field 30"
              }, {
                  "Wells": {
                      "Well": "Well 140"
                  },
                  "name": "Field 40"
              }],
              "name": "AndersonSouth"
          },
          "name": "South America"
      }],
      "name": "ABC Oil Co"
  }];
  </code></pre>
  
  <p>I want to search based on a key supplied and return a specific object containing that key.</p>
  
  <p>For example : if I pass <code>key = "North America"</code>, I will get:</p>
  
  <pre><code>{
      "Area": [{
          "Asset": [{
              "Wells": {
                  "Well": "Well 11"
              },
              "name": "Field 1"
          }, {
              "Wells": {
                  "Well": "Well 12"
              },
              "name": "Field 2"
          }],
          "name": "Archer"
      }, {
          "Asset": [{
              "Wells": {
                  "Well": "Well 13"
              },
              "name": "Field 3"
          }, {
              "Wells": {
                  "Well": "Well 14"
              },
              "name": "Field 4"
          }],
          "name": "Anderson"
      }],
      "name": "North America"
  }
  </code></pre>
  
  <p>I tried this </p>
  
  <pre><code>function search(nameKey, myArray) {
              for (var i = 0; i &lt; myArray.length; i++) {
                  if (myArray[i].name === nameKey) {
                      return myArray[i];
                  }
              }
          }
  </code></pre>
  
  <p>But since my array of object again contain more array of objects . It was not helpful.</p>