takeWhile(predicate[, arg])

suckgamoni edited this page May 15, 2013 · 1 revision

Returns elements from a sequence as long as a specified condition is true. The element's index is used in the logic of the predicate function.

Syntax

Parameters

predicate

Type: function(value, key, arg): boolean
A function to test each source element for a condition; the second parameter of the function represents the index of the source element.

arg

An external argument.

Return Value

An iterable object that contains elements from the input sequence that occur before the element at which the test no longer passes.


Example

var fruits = [ "apple", "passionfruit", "banana", "mango", "orange", "blueberry", "grape", "strawberry" ];

var query = from(fruits).takeWhile("$length >= $$");
query.each("console.log($)");

/*
 This code produces the following output:

 apple
 passionfruit
 banana
 mango
 orange
 blueberry
*/