live-server icon indicating copy to clipboard operation
live-server copied to clipboard

Use String#includes to see if a substring exists instead of indexOf

Open andria-dev opened this issue 4 years ago • 0 comments

In live-server.js I noticed that you're using String#indexOf to see if an item exists in an array as opposed to the more appropriate String#includes. I doubt there's enough of a performance difference to truly matter but it's much more readable.

It also is slightly less characters overall to use .includes() than .indexOf() > -1

For example:

/* OLD */
if (arg.indexOf("--port=") > -1) {
}

/* NEW */
if (arg.includes("--port=")) {
}

andria-dev avatar Dec 31 '19 01:12 andria-dev