通知短信+运营短信,5秒速达,支持群发助手一键发送🚀高效触达和通知客户 广告
## takeWhile + [link](./takeWhile "Link to this entry.") + [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L6766 "View in source.") + [npm](https://www.npmjs.com/package/lodash.takewhile "See the npm package.") ``` _.takeWhile(array, [predicate=_.identity]) ``` 从数组的开始提取数组,直到 predicate 返回假值。predicate 会传入三个参数:(value, index, array)。 ### 参数 1. array (Array) 需要处理的数组 2. [predicate=_.identity] (Function|Object|string) 这个函数会处理每一个元素 ### 返回值 (Array) 返回提取的元素数组 ### 示例 ``` var users = [ { 'user': 'barney', 'active': false }, { 'user': 'fred', 'active': false}, { 'user': 'pebbles', 'active': true } ]; _.takeWhile(users, function(o) { return !o.active; }); // => objects for ['barney', 'fred'] // 使用了 `_.matches` 的回调处理 _.takeWhile(users, { 'user': 'barney', 'active': false }); // =>结果: ['barney'] // 使用了 `_.matchesProperty` 的回调处理 _.takeWhile(users, ['active', false]); // =>结果: ['barney', 'fred'] // 使用了 `_.property` 的回调处理 _.takeWhile(users, 'active'); // => [] ```