angular.Array.indexOf

Description

Determines the index of a value in an array.

Note: This function is used to augment the Array type in Angular expressions. See angular.Array for more information about Angular arrays.

Usage

angular.Array.indexOf(array, value);

Parameters

Returns

{number}

The position of the element in array. The position is 0-based. If the value cannot be found, -1 is returned.

Example

 <div ng:init="books = ['Moby Dick', 'Great Gatsby', 'Romeo and Juliet']"></div>
 <input name='bookName' value='Romeo and Juliet'> <br>
 Index of '{{bookName}}' in the list {{books}} is <em>{{books.$indexOf(bookName)}}</em>.
 it('should correctly calculate the initial index', function() {
   expect(binding('books.$indexOf(bookName)')).toBe('2');
 });

 it('should recalculate', function() {
   input('bookName').enter('foo');
   expect(binding('books.$indexOf(bookName)')).toBe('-1');

   input('bookName').enter('Moby Dick');
   expect(binding('books.$indexOf(bookName)')).toBe('0');
 });