Namespace: some

async.some

Source:

Examples

// array
var order = [];
var array = [1, 3, 2];
var iterator = function(num, done) {
  setTimeout(function() {
    order.push(num);
    done(null, num % 2);
  }, num * 10);
};
async.some(array, iterator, function(err, res) {
  console.log(res); // true
  console.log(order); // [1]
});
// array with index
var order = [];
var array = [1, 3, 2];
var iterator = function(num, index, done) {
  setTimeout(function() {
    order.push([num, index]);
    done(null, num % 2);
  }, num * 10);
};
async.some(array, iterator, function(err, res) {
  console.log(res); // true
  console.log(order); // [[1, 0]]
});
// object
var order = [];
var object = { a: 1, b: 3, c: 2 };
var iterator = function(num, done) {
  setTimeout(function() {
    order.push(num);
    done(null, num % 2);
  }, num * 10);
};
async.some(object, iterator, function(err, res) {
  console.log(res); // true
  console.log(order); // [1]
});
// object with key
var order = [];
var object = { a: 1, b: 3, c: 2 };
var iterator = function(num, key, done) {
  setTimeout(function() {
    order.push([num, key]);
    done(null, num % 2);
  }, num * 10);
};
async.some(object, iterator, function(err, res) {
  console.log(res); // true
  console.log(order); // [[1, 'a']]
});