collection(2)--detect
2016-07-25 本文已影响9人
LuciferTM
detect
功能:用于取得集合中满足条件的第一个元素。它分为并行与顺序执行两种方式,分别对应函数detect、detectLimit、detectSeries。
接口:
detect(array, iterator(item,callback(test)), callback(result)
detectLimit(array, limit,iterator(item,callback(test)), callback(result)
detectSeries(array, iterator(item,callback(test)), callback(result)
测试数据

detect
代码:

结果:

detectLimit
detectLimit使用limit参数显示同时并行的个数,当然如果limit=1,那么等效为detectSeries。
代码:

结果:

detectSeries
代码:

结果:
