Skip to content

Commit

Permalink
[DOC] #18228 Update documentation and examples for EmberArray.… (#18466)
Browse files Browse the repository at this point in the history
[DOC] #18228 Update documentation and examples for EmberArray.indexOf
  • Loading branch information
rwjblue authored Oct 10, 2019
2 parents 315ec64 + 078f7fa commit 9a09374
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions packages/@ember/-internals/runtime/lib/mixins/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,20 +377,34 @@ const ArrayMixin = Mixin.create(Enumerable, {
},

/**
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.
Used to determine the passed object's first occurence in the array.
Returns the index if found, -1 if no match is found.
The optional `startAt` argument can be used to pass a starting
index to search from, effectively slicing the searchable portion
of the array. If it's negative it will add the array length to
the startAt value passed in as the index to search from. If less
than or equal to `-1 * array.length` the entire array is searched.
```javascript
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('a', -1); // 4, equivalent to indexOf('a', 4)
arr.indexOf('a', -100); // 0, searches entire array
arr.indexOf('b', 3); // -1
arr.indexOf('a', 100); // -1
let people = [{ name: 'Zoey' }, { name: 'Bob' }]
let newPerson = { name: 'Tom' };
people = [newPerson, ...people, newPerson];
people.indexOf(newPerson); // 0
people.indexOf(newPerson, 1); // 3
people.indexOf(newPerson, -4); // 0
people.indexOf(newPerson, 10); // -1
```
@method indexOf
Expand Down

0 comments on commit 9a09374

Please sign in to comment.