title: Best way to replace missing/undefined values in an array?
body: <p>I need to process some arrays that contains <code>undefined</code> values, like the following:</p>
  
  <pre><code>[ 1, 1, 1, 1, 1, , 1, 1 ]
  [ 1, , 1, , , 1, 1 ]
  [ 1, , , , , 1, 1 ]
  </code></pre>
  
  <p>What I need to achieve is <strong>not</strong> a removal of the <code>undefined</code> values, but I need to <strong>replace</strong> them with zeros.</p>
  
  <p>I tried to use <a href="http://underscorejs.org" rel="nofollow">underscore.js</a> to achieve this; without success.</p>
  
  <p>The following is my solution attempt:</p>
  
  <pre><code>binarymap = _.map(binarymap, function(curr){
      // let's replace all undefined with 0s
      if(_.isUndefined(curr)) {
          return 0;
      }
      return curr;
  });
  </code></pre>
  
  <p>Unfortunately, it does not work. <em>underscore.js</em>'s function <code>_.map</code> totally ignores <code>undefined</code> values.</p>
  
  <p>Any ideas? Elegant solutions?</p>