• function

indexOf can.Observe.List.prototype.indexOf


Look for an item in a List.


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


  1. item {*}

    the item to find



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

var list = new can.Observe.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;