linq.Last

Gets the last element in the array. Throws an exception if the array contains zero elements.

Overloads

  • Object Last ()
  • Object Last (condition)

Object Last ()

Gets the last element in the array
var myArray = [1, 2, 3, 4];
//Returns 4
myArray.Last();

myArray = [];
//Throws an exception
myArray.Last();

Object Last (condition)

Gets the last element in the array where the specified condition is met

Example

var myArray = [1,3,4,5];
//Returns 5
myArray.Last("x => x % 2 == 1");

//Throws an exception
myArray.Last("x => x == 42");

Last edited Sep 24, 2011 at 4:09 AM by mlorbetske, version 2

Comments

No comments yet.