Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate jQuery.inArray #4204

Closed
KingSora opened this Issue Oct 24, 2018 · 4 comments

Comments

Projects
None yet
4 participants
@KingSora
Copy link

KingSora commented Oct 24, 2018

If I'm not overlooking something this is fullfilled with Array.prototype.indexOf() and therefore it should be deprecated like #2961.

@mgol

This comment has been minimized.

Copy link
Member

mgol commented Oct 24, 2018

Thanks for the issue!

Array#indexOf is not that nice an API for this purpose as its intent is not clear. The true replacement is Array#includes but its browser support is not that great (that is, no IE support). Recently, we mostly deprecated APIs that had native equivalents in all supported browsers or that were too unclear had too many edge cases for us to handle (like jQuery.isNumeric).

That said, using Array#indexOf for this purpose is widespread so maybe it's OK. I don't have a definite opinion.

@timmywil

This comment has been minimized.

Copy link
Member

timmywil commented Oct 29, 2018

We reviewed this in the weekly meeting. I agree the exact replacement doesn't have full support in our supported browsers. And jQuery.inArray is short and there's no rush to deprecate.

@timmywil timmywil closed this Oct 29, 2018

@edg2s

This comment has been minimized.

Copy link
Contributor

edg2s commented Jan 22, 2019

The true replacement is Array#includes

By name, yes, but inArray is badly named in that it is actually returns an index, not a Boolean. So really indexOf is the correct replacement for current uses of inArray.

@mgol

This comment has been minimized.

Copy link
Member

mgol commented Jan 22, 2019

@edg2s Good point about the returned index. In that case, though, it'd be closest to Array#findIndex but that method doesn't support the fromIndex parameter unlike Array#include. So there's no perfect replacement but that would be the closest one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.