Skip to content

lib: prefer using Array#includes instead of Array#indexOf #26568

Closed
@starkwang

Description

@starkwang

In our lib code, we are still using Array#indexOf to determine if an item is existed in array.

For example:

node/lib/url.js

Line 584 in 3414bc7

this.hostname.indexOf(':') === -1 ?

if (str.indexOf("'") !== -1) {

For semantics, I think it's more appropriate to move them into Array#includes and it seems no performance difference between them at present: https://jsperf.com/array-indexof-vs-includes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions