Skip to content

Files

Latest commit

 

History

History
21 lines (14 loc) · 515 Bytes

prefer_contains.md

File metadata and controls

21 lines (14 loc) · 515 Bytes

Pattern: Missing use of contains

Issue: -

Description

Calling indexOf to see if a collection contains something is difficult to read and may have poor performance. Use contains instead.

Example of correct code:

if (!lunchBox.contains('sandwich') return 'so hungry...';

Example of incorrect code:

if (lunchBox.indexOf('sandwich') == -1 return 'so hungry...';

Further Reading