You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yasser Moradi edited this page Aug 26, 2015
·
2 revisions
Description:
As the name may suggest, this method retrieves items from the start of a sequence based on a passed predicate results. This predicate gets evaluated for each item in the collection until the first time that predicate returns false for one item.
The following sample code retrieves items from the start of the array until a string with a length of ten
or more characters is encountered.Even though further items exist in the array that pass the condition,
these are not returned.
Samples:
letfruits=['Apple','Banana','Cherry','Damson','Elderberry','Grape','Kiwi','Lemon','Melon','Orange'];console.log('TakeWhile method continues retrieving items unti string length be bigger or equal than 10 ...');lettakeWhilePartitioned=fruits.asEnumerable().takeWhile(f=>f.length<10).toArray();for(letindex=0;index<takeWhilePartitioned.length;index++)console.log(takeWhilePartitioned[index]);