- Lodash Tutorial
- Lodash - Home
- Lodash - Overview
- Lodash - Environment Setup
- Lodash - Array
- Lodash - Collection
- Lodash - Date
- Lodash - Function
- Lodash - Lang
- Lodash - Math
- Lodash - Number
- Lodash - Object
- Lodash - Seq
- Lodash - String
- Lodash - Util
- Lodash - Properties
- Lodash - Methods
- Lodash Useful Resources
- Lodash - Quick Guide
- Lodash - Useful Resources
- Lodash - Discussion
Lodash - takeWhile method
Syntax
_.takeWhile(array, [predicate=_.identity])
Creates a slice of array with elements taken from the beginning. Elements are taken until predicate returns falsey. The predicate is invoked with three arguments: (value, index, array).
Arguments
array (Array) − The array to query.
[predicate=_.identity] (Function) − The function invoked per iteration.
Output
(Array) − Returns the slice of array.
Example
var _ = require('lodash'); var users = [ { 'user': 'Mark', 'active': false }, { 'user': 'Joe', 'active': true }, { 'user': 'Jake', 'active': false } ]; var result = _.takeWhile(users, function(o) { return !o.active; }); console.log(result);
Save the above program in tester.js. Run the following command to execute this program.
Command
\>node tester.js
Output
[ { user: 'Mark', active: false } ]
lodash_array.htm
Advertisements