This project is read-only.

lastIndexOf()

The lastIndexOf linq operator returns the zero-based index of the last element that satisfies the predicate. The lastIndexOf operator returns the value -1 if none of the elements satisfy the predicate.
var arr1 = ["First", "Second", "Third", "Fourth", "Fifth"];

var arr2 = [{name: "Alesia", favoriteColor: "yellow"},
    {name: "Tim", favoriteColor: "red"},
    {name: "Zachary", favoriteColor: "blue"},
    {name: "Lily", favoriteColor: "blue"}];
    
// val1 = 4
var val1 = $linq(arr1).lastIndexOf("x => x[0] == 'F'");

// val2 = 3
var val2 = $linq(arr2).lastIndexOf("x => x.favoriteColor == 'blue'");

lastIndexOfElement()

The lastIndexOfElement linq operator returns the zero-based index of the last element that is equal (according to the === operator) to the "item" parameter. The lastIndexOfElement operator can also take a "comparer" function that is used to determine equality between the elements of the collection and the "item" parameter.
var arr1 = [99, 121, 771, 889, 1024, 889];
var arr2 = ["YELLOW", "RED", "YELLOW", "BLUE", "BLUE"];

// val1 = 5
var val1 = $linq(arr1).lastIndexOfElement(889);

// val2 = 2
var val2 = $linq(arr2).indexOfElement("yellow", "(x, y) => x.toLowerCase() == y.toLowerCase()");

Last edited Nov 30, 2012 at 6:15 PM by battousai999, version 1