question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule proposal: `prefer-array-find`

See original GitHub issue

Prefer .find() over .filter()[0], since find breaks the loop as soon as it finds a match.

Fail

const item = array.filter(x => x === '🦄')[0];

Pass

const item = array.find(x => x === '🦄');

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
fiskercommented, May 16, 2020

Fail

const item = array.filter(x => x === '🦄').shift();
1reaction
sindresorhuscommented, May 17, 2020

Accepted. PR welcome.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rule proposal: `prefer-array-some` #736 - Issuehunt
I like the idea of suggesting some . Might help users who don't know any better. BTW, I did a rule to eslint...
Read more >
C++ Core Guidelines - GitHub Pages
assignment: regular types – prefer initialization – copy – move – other ... You will find some of the rules contrary to your...
Read more >
Medicare Program: Prospective Payment ... - Regulations.gov
This proposed rule would update: Payment rates; forecast error adjustment; ... Follow the search instructions on that website to view public comments.
Read more >
Details of the policy definition structure - Azure - Microsoft Learn
This policy rule example uses the resourceGroup resource function to get the name property, combined with the concat array and object function ...
Read more >
Proposed Rule: Further Definition of “As a Part of a Regular ...
The Commission has neither approved nor disapproved the content of these staff documents and, like all staff statements, they have no legal ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found