Skip to content

join(inner, outerKeySelector, innerKeySelector, resultSelector[, comparer, arg])

suckgamoni edited this page · 1 revision

Correlates the elements of two sequences based on matching keys. A specified equality comparer is used to compare keys.

Syntax

Parameters

inner

The sequence to join to the first sequence.

outerKeySelector

Type: function(value, key, arg)
A function to extract the join key from each element of the first sequence.

innerKeySelector

Type: function(value, key, arg)
A function to extract the join key from each element of the second sequence.

resultselector

Type: function(outerValue, innerValue, arg)
A function to create a result element from two matching elements.

comparer

Type: function(value1, value2, arg): boolean
An equality comparer to hash and compare keys.

arg

An external argument.

Return Value

An iterable object that has elements of type TResult that are obtained by performing an inner join on two sequences.


Example

var magnus = { name: "Hedlund, Magnus" };
var terry = { name: "Adams, Terry" };
var charlotte = { name: "Weiss, Charlotte" };

var barley = { name: "Barley", owner: terry };
var boots = { name: "Boots", owner: terry };
var whiskers = { name: "Whiskers", owner: charlotte };
var daisy = { name: "Daisy", owner: magnus };

var people = [ magnus, terry, charlotte ];
var pets = [ barley, boots, whiskers, daisy ];

// Create a list of Person-Pet pairs where 
// each element is an anonymous type that contains a
// Pet's name and the name of the Person that owns the Pet.
var query =
    from(people).join(pets,
        "person => person",
        "pet => pet.owner",
        function (person, pet) {
            return { ownerName: person.name, pet: pet.name };
        }
    );

query.each("console.log($ownerName + ' - ' + $pet)");

/*
 This code produces the following output:

 Hedlund, Magnus - Daisy
 Adams, Terry - Barley
 Adams, Terry - Boots
 Weiss, Charlotte - Whiskers
*/
Something went wrong with that request. Please try again.