This project is read-only.

atOrDefault(index, defValue)

Returns the element at a specified index in a sequence or a default value if the index is out of range.



Type: number
The zero-based index of the element to retrieve.
Default value to return.
Return Value

defValue if the index is outside the bounds of the source sequence; otherwise, the element at the specified position in the source sequence.


var names = [ "Hartono, Tommy", "Adams, Terry", "Andersen, Henriette Thaulow",  "Hedlund, Magnus", "Ito, Shu" ];

var index = 20;
var name0 = $from(names).atOrDefault(index, null);

document.writeln("The name chosen at index " + index + " is '" + (name0 == null ? "[no name at this index]" : name0) + "'.");

 This code produces the following output:

 The name chosen at index 20 is '[no name at this index]'.

Last edited May 15, 2012 at 1:31 PM by suckgamoni, version 2


No comments yet.