linq.Distinct

Determines whether an array contains a specific element

Overloads

  • Array Distinct ()
  • Array Distinct (selector)
  • Array Distinct (selector, equalityComparer)

Array Distinct ()

Returns the set of unique elements within the array

Example

var myArray = [1,3,4,4,4,5];
//Returns [1,3,4,5]
myArray.Distinct();

Array Distinct (selector)

Returns the set of unique elements within the array using the selector to determine the member used for equality comparison
var myArray = [{a:1, b:2}, {a:1, b:3}, {a:2, b:2}];
//Returns [{a:1, b:2}, {a:1, b:3}]
myArray.Distinct("x=>x.b");

Array Distinct (selector, equalityComparer)

Returns the set of unique elements within the array using the selector to determine the member used by the specified equalityComparer.
Specifying null for selector uses the default selector "x=>x"

Example

var myArray = [{a:1, b:2}, {a:1, b:3}, {a:2, b:2}];
//Returns [{a:1, b:2}, {a:1, b:3}]
myArray.Distinct(null, "(a, b)=>a.b == b.b");

Last edited Sep 23, 2011 at 4:16 AM by mlorbetske, version 1

Comments

No comments yet.