The elementAt linq operator returns the element of the collection located at the 0-based index given. If the index is out of the bounds of the collection (i.e., less than zero or greater than or equal to the length of the collection), then an exception will be thrown.
var arr = ['a', 'b', 'c', 'd', 'e', 'f'];

// val = 'c'
var val = $linq(arr).elementAt(2);


The elementAtOrDefault linq operator behaves like the elementAt operator, except that if the index is out of the bounds of the collection, the elementAtOrDefault operator returns the given "default value" (rather than throwing an exception).
var arr = ['a', 'b', 'c', 'd', 'e', 'f'];

// val1 = 'c'
var val1 = $linq(arr).elementAtOrDefault(2, 'none');

// val2 = 'none'
var val2 = $linq(arr).elementAtOrDefault(99, 'none');

Last edited Sep 11, 2012 at 10:26 PM by battousai999, version 2