takeWhile(predicate[, arg])

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 iteratable object that contains elements from the input sequence that occur before the element at which the test no longer passes.

Examples

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

var query = $from(fruits).takeWhile("$length >= $$");
query.each("document.writeln($)");

/*
 This code produces the following output:

 apple
 passionfruit
 banana
 mango
 orange
 blueberry
*/

Last edited May 18, 2012 at 10:53 AM by suckgamoni, version 1

Comments

No comments yet.