title: Alert user if there is a duplicate value in array
body: <p>I have a recursive array structure like below:</p>
  
  <pre><code>var trees = [{
      name: "Node-1",
      myObj : { name : "Node-1"},
      nodes: 
      [
             {   name: "Node-1-1", myObj : { name : "Node-1"}, nodes[]}
      ]
    },{
      name: "Node2",
      myObj : { name : "Abc"},
      nodes: []
    }];
  
  var obj = {
      name: "Node-1-1",
      myObj : { name : "Node-1"},
      nodes: []
    }
  </code></pre>
  
  <p>Now I want to match obj.myObj.name value in trees array and if found then it should return true or false immediately and stop further traversing through the tree and alert the user regarding duplicate found.</p>
  
  <p>Now as you can <code>obj.myObj.name</code> value is matching with first record so I want to alert user but I am always getting false.</p>
  
  <p>Here <code>obj.myObj.name</code> value i.e Node-1 is matching with first record of <code>trees[0].myObj.name</code> so I want to alert user.</p>
  
  <p><strong>Update :</strong> </p>
  
  <p>Based on answer given on this question i have change the code and sample input but now when I have Pqr in <code>trees[0].myObj.name</code> and obj contains pqr so while searching obj value in trees I want to skip pqr value from trees as because pqr doesn't exist in other trees record still I am getting pqr exist.</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>var trees = [{
      name: "Node-1",
      myObj : { name : "Pqr"},
      nodes: 
   [
             {   name: "Node-1-1", myObj : { name : "Abc"}, nodes:[]}
   ]
    },{
      name: "Node2",
      myObj : { name : "Abc"},
      nodes: []
    }];
  
  var obj = {
      name: "Node-1-1",
      myObj : { name : "Pqr"},
      nodes: []
    }
    
    checkDuplicateNodeName();
    
    function checkDuplicateNodeName() {
          var name = obj.myObj.name;
          var dupe = false;
          for(var idx = 0; idx &lt; trees.length; idx++) {
              if(trees[idx].myObj.name != name)
                  continue;
              if(isDuplicateName(trees[idx], name))
              {
                  dupe = true;
                  break;
              }
          }
          if(dupe){
              alert('The name "' + name + ' already exists');
          }
          else
              alert('All is well');
      }
  
  function isDuplicateName(node, name) {
          var dupeName = node.myObj.name &amp;&amp; name &amp;&amp; node.myObj.name.toLowerCase() == name.toLowerCase();
          if(dupeName) return true;
      
          if(node.nodes){
              for(var idx=0; idx&lt; node.nodes.length; idx++) {
                  if(isDuplicateName(node.nodes[idx], name)){
                      return true;
                  }
              }
          }
          return false;
      }</code></pre>
  </div>
  </div>
  </p>