Opened 2 years ago

Closed 2 years ago

#6737 closed change (fixed)

Use String.includes instead of String.indexOf where the index is not needed

Reported by: mjethani Assignee: mjethani
Priority: P3 Milestone:
Module: Core Keywords:
Cc: sergz, kzar, jsonesen Blocked By:
Blocking: #6425 Platform: Unknown / Cross platform
Ready: yes Confidential: no
Tester: Unknown Verified working: no
Review URL(s):



We use String.indexOf and compare the return value with -1 when we want to check if a string contains a given string. ECMAScript 2015 introduced a new String.includes method which is a lot more straightforward and does not affect performance negatively. It is supported on all our supported platforms.

What to change

Where the index of a search string is irrelevant and the objective is only to check if the search string occurs anywhere in a given string, replace the use of String.indexOf with String.includes.

Change History (3)

comment:1 Changed 2 years ago by mjethani

  • Review URL(s) modified (diff)
  • Status changed from new to reviewing

comment:2 Changed 2 years ago by abpbot

A commit referencing this issue has landed:
Issue 6737 - Use String.includes instead of String.indexOf

comment:3 Changed 2 years ago by mjethani

  • Resolution set to fixed
  • Status changed from reviewing to closed
Note: See TracTickets for help on using tickets.