Skip to content
Yasser Moradi edited this page Aug 30, 2015 · 2 revisions

Description:

One of the main tasks of a LINQ query is to restrict the results from a larger collection based on some criteria. This is achieved using the Where operator, which tests each element within a source collection and returns only those elements that return a true result when tested against a given predicate expression. A predicate is simply an expression that takes an element of the same type of the items in the source collection and returns true or false.

Samples:

let animals = ["Koala", "Kangaroo", "Spider", "Wombat", "Snake", "Emu", "Shark", "Sting-Ray", "Jellyfish"];
let q = animals.asEnumerable()
  .where(a => a.indexOf("S") === 0 && a.length > 5)
/*You can write following where instead:
  .where((a,index) => index is index of a, you can write more complex predicates then. )*/
  .toArray();

console.log('using where clause ...');

for (let index = 0; index < q.length; index++)
  console.log(q[index]);
Clone this wiki locally