title: Getting return value for Array.forEach function
body: <p>I'm stucked with the following function, trying to get back a value (a part of a dom tree).</p>
  <p>Instead of receiving a useful value I just obtain a <code>0/undefined</code>.</p>
  <pre><code>var findNodeForAttributeValue = function (node, innerXmlAttributeName, innerXmlAttributeValue) {
  var indirectReturnVar='0';
  if ((node.nodeType === 1)&amp;&amp;(node.hasAttribute(innerXmlAttributeName))) {
      if (node.getAttribute(innerXmlAttributeName)==innerXmlAttributeValue) {
          indirectReturnVar=node;
          return indirectReturnVar;
      }
  }
  if((node.hasChildNodes())&amp;&amp;(node.firstChild!=null)) {
      Array.forEach ( node.childNodes, function (children) {
          findNodeForAttributeValue(children, innerXmlAttributeName, innerXmlAttributeValue);
      } );
      return indirectReturnVar;
  }
  </code></pre>
  <h3 id="edit-xx3x">Edit</h3>
  <p>Updated code:</p>
  <pre><code>var findNodeForAttributeValue = function (node, innerXmlAttributeName, innerXmlAttributeValue) {
    var indirectReturnVar='0';
    if ((node.nodeType === 1) &amp;&amp; (node.hasAttribute(innerXmlAttributeName))) {
      if (node.getAttribute(innerXmlAttributeName) == innerXmlAttributeValue) {
        indirectReturnVar = node;
        return indirectReturnVar;
      }
    }
  
    if ((node.hasChildNodes()) &amp;&amp; (node.firstChild != null)) {
      for (var fi=0, fiLen=node.childNodes.length; fi&lt;fiLen; fi++) {
        findNodeForAttributeValue(node.childNodes[fi], innerXmlAttributeName, innerXmlAttributeValue);
      }
      return indirectReturnVar;
    }
  }
  </code></pre>