indexOf

  • function
can.List.prototype.indexOf  

Look for an item in a List.

list.indexOf(item)

indexOf finds the position of a given item in the List.

Parameters

  1. item {*}

    the item to find

Returns

{Number}

the position of the item in the List, or -1 if the item is not found.

var list = new can.List(['Alice', 'Bob', 'Eve']);
list.indexOf('Alice');   // 0
list.indexOf('Charlie'); // -1

It is trivial to make a contains-type function using indexOf:

function(list, item) {
    return list.indexOf(item) >= 0;
}