contains(value[, comparer, arg])

Determines whether a sequence contains a specified element by using a specified equality comparer.

Syntax

Parameters

value
The value to locate in the sequence.
comparer
Type: function(a, b, arg): boolean
An equality comparer.
arg
An external argument
Return Value

Type: boolean
true if the source sequence contains an element that has the specified value; otherwise, false.

Examples

var fruits = [ "apple", "banana", "mango", "orange", "passionfruit", "grape" ];

var fruit = "mango";

var hasMango = $from(fruits).contains(fruit);

document.writeln("The array " + (hasMango ? "does" : "does not") + " contain '" + fruit + "'.");

// This code produces the following output:
//
// The array does contain 'mango'. 

var fruits = [ { name: "apple", code: 9 },
               { name: "orange", code: 4 }, 
               { name: "lemon", code: 12 } ];

var apple = { name: "apple", code: 9 };
var kiwi = {name: "kiwi", code: 8 };

var comparer = "(#0 == #1) || (#0 && #1 && #0.code == #1.code && #0.name == #1.name)";

var fruitsIteratable = $from(fruits);
var hasApple = fruitsIteratable.contains(apple, comparer);
var hasKiwi = fruitsIteratable.contains(kiwi, comparer);

document.writeln("Apple? " + hasApple);
document.writeln("Kiwi? " + hasKiwi);

/*
	This code produces the following output:

	Apple? true
	Kiwi? false
*/    

Last edited May 16, 2012 at 4:59 AM by suckgamoni, version 4

Comments

No comments yet.