Skip to content

Instantly share code, notes, and snippets.

@Philmod
Created January 21, 2015 19:38
Show Gist options
  • Save Philmod/d09464626b5ed0c92ab0 to your computer and use it in GitHub Desktop.
Save Philmod/d09464626b5ed0c92ab0 to your computer and use it in GitHub Desktop.
Async with a null value returned
var async = require('async')
, _ = require('underscore');
var array = [1,2,3,4,5];
async.map(array, function(item, cb) {
if (item === 3)
return cb();
else
return cb(null, item*2);
}, function(e, newArray) {
console.log('End error : ', e);
console.log('End array : ', newArray);
console.log('Compact : ', _.compact(newArray));
});
/*
End error : undefined
End array : [ 2, 4, undefined, 8, 10 ]
Compact : [ 2, 4, 8, 10 ]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment