title: LeetCode Two Sums problem - Result undefined
body: <p>First stack overflow question :)</p>
  <p>My code is returning &quot;undefined&quot; as the result. Can someone please tell me why?</p>
  <p>Question: Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.</p>
  <p>Test Case: Input: nums = [2,7,11,15], target = 9 <br />
  My Output: undefined <br />
  Correct Output: [0,1]</p>
  <pre><code>/**
   * @param {number[]} nums
   * @param {number} target
   * @return {number[]}
   */
  var twoSum = function(nums, target) {
      
      // iterate through each element  
      nums.forEach((element, index) =&gt; {
        
          // iterate through the rest of the array
          nums.forEach((el, i) =&gt; {
              // makes sure it isnt adding the same index
              if(index != i) {
                  if(element+el == target){
                      return [index, i];
                  }
              }
  
          })
      })
  };
  </code></pre>