Array#indexOf()

indexOf (object, startAt) Numberpublic

Defined in packages/ember-runtime/lib/mixins/array.js:370

Returns the index of the given object's first occurrence. If no startAt argument is given, the starting location to search is 0. If it's negative, will count backward from the end of the array. Returns -1 if no match is found.

let arr = ['a', 'b', 'c', 'd', 'a'];

arr.indexOf('a');       //  0
arr.indexOf('z');       // -1
arr.indexOf('a', 2);    //  4
arr.indexOf('a', -1);   //  4
arr.indexOf('b', 3);    // -1
arr.indexOf('a', 100);  // -1

Parameters:

object Object
the item to search for
startAt Number
optional starting location to search, default 0

Returns:

Number
index or -1 if not found
doc_EmberJs
2016-11-30 16:48:34
Comments
Leave a Comment

Please login to continue.