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

Use Array.prototype.find() instead of .filter()[0] #56

Open
Glavin001 opened this issue Jul 11, 2018 · 1 comment
Open

Use Array.prototype.find() instead of .filter()[0] #56

Glavin001 opened this issue Jul 11, 2018 · 1 comment

Comments

@Glavin001
Copy link
Owner

Glavin001 commented Jul 11, 2018

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find

const items = [
  { id: 123 },
  { id: 456 }
  // ...
];
const selectedId = 456;
const selectedItem = items.filter(item => item.id === selectedIds)[0];

Should be:

// ...
const selectedItem = items.find(item => item.id === selectedIds);

Diff:

- const selectedItem = items.filter((item) => item.id === selectedIds)[0];
+ const selectedItem = items.find((item) => item.id === selectedIds);
@mhelin
Copy link

mhelin commented Dec 18, 2019

IE11 doesn't support find

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

No branches or pull requests

2 participants