Note: this function is used to augment the Array type in angular expressions. See
angular.Array for more info.
Usage
angular.Array.indexOf(array, value);
Parameters
array – {Array} –
Array to search.
value – {*} –
Value to search for.
Returns
number
– The position of the element in array. The position is 0-based. -1 is returned if the value can't be found.
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');
});