selectMany(selector[, arg])

Projects each element of a sequence to an iteratable object and flattens the resulting sequences into one sequence.

Syntax

Parameters

selector
Type: function(value, key, arg)
A transform function to apply to each element.
arg
An external argument.
Return Value

An iteratable object whose elements are the result of invoking the one-to-many transform function on each element of the input sequence.

Examples

var petOwners = [
    { name: "Higa, Sidney", 
      pets: [ "Scruffy", "Sam" ] },
    { name: "Ashkenazi, Ronen", 
      pets: [ "Walker", "Sugar" ] },
    { name: "Price, Vernette", 
      pets: [ "Scratches", "Diesel" ] } ];

// Query using SelectMany().
var query1 = $from(petOwners).selectMany("$pets");

// Only one foreach loop is required to iterate 
// through the results since it is a
// one-dimensional collection.
query1.each("document.writeln($)");

/*
This code produces the following output:

Scruffy
Sam
Walker
Sugar
Scratches
Diesel
*/

Last edited May 18, 2012 at 9:41 AM by suckgamoni, version 2

Comments

No comments yet.