title: Javascript - How to return from a loop in a callback?
body: <pre class="lang-js prettyprint-override"><code>const arr = [36,19,69,27];
  
  function push_to_array(data, cb){
    for(let i=0; i &lt; data.length; i++){
        cb(data[i]);
    }
  }
  
  let test = push_to_array(arr, function(item){
      console.log(item);
      return item
  });
  console.log(test)
  </code></pre>
  
  <p>I apologize in advance for any lack in knowledge, I'm trying to wrap my head around Callbacks and Higher order Functions.  </p>
  
  <p>I'm attempting to loop in my callback function and return each value in the array. Right now the <code>console.log(item)</code> is showing that I'm indeed getting each value, but the return is saying that I am getting undefined.  I'm not quite sure why and was just wondering what I'm doing wrong.</p>
  
  <p>Thank you.</p>