Skip to content

Array#findIndex and Array#findIndexBy - #246

Closed
buschtoens wants to merge 2 commits into
emberjs:masterfrom
buschtoens:array-find-index
Closed

Array#findIndex and Array#findIndexBy#246
buschtoens wants to merge 2 commits into
emberjs:masterfrom
buschtoens:array-find-index

Conversation

@buschtoens

Copy link
Copy Markdown
Contributor

@kellyselden

Copy link
Copy Markdown
Member

My understanding of the Ember Array API (and Object) are basically frozen as we move away from them and/or extract them?

@locks locks added the T-framework RFCs that impact the ember.js library label Sep 1, 2017
@mmun

mmun commented Mar 1, 2018

Copy link
Copy Markdown
Member

Kelly's right. The Ember.Array API is frozen. In the future we may move the Array/ArrayProxy classes to an addon where they can be iterated on.

If you're working with a native array and you're targeting modern browsers (i.e. not IE11) then you can just use the native Array.prototype.findIndex. If you are targetting IE11, then you'll need to use something like ember-lodash.

If you need to support more general usages of the Ember.Array mixin that rely on objectAt then must first map the object to a native array using toArray():

post.get('comments').toArray().findIndex(comment => {
  return comment.get('title') == "Hello world"
});

@mmun mmun closed this Mar 1, 2018
@aalimovs

aalimovs commented Sep 4, 2018

Copy link
Copy Markdown

@mmun FYI, with toArray() the order is not guaranteed, see here. Not sure why though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-framework RFCs that impact the ember.js library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants