异步等同于节点 js 中的 array.some()

asynchronous equivilent to array.some() in nodejs

我需要遍历一个集合,检查每个集合是否作为一行存在于我的数据库中

是否有 .some() 异步等价物用于汇总整个集合的异步 true/false 检查结果?

您可以使用 async 模块,特别是这个方法 async.each https://github.com/caolan/async#each

https://www.npmjs.com/package/async 这是 npm 包

添加了一个小示例(而不是我的 if 你会想要检查你的数据库)

var tests = ['a', 'b'];
async.each(tests, function(test, callback) {

  if(test === 'c') {
    return callback('We cannot have a c')
  }

  return callback();
}, function(err){
    // if any of the file processing produced an error, err would equal that error
    if( err ) {
      // One of the iterations produced an error.
      // All processing will now stop.
      console.log('C was found');
    } else {
      console.log('All Tests are ok');
    }
});