Use string.startsWith()

string.startsWith() checks if a string starts with another string.

Refactoring
Modernization
ES2015
P42 for VS Code
P42 for GitHub
Use string.startsWith()

String.prototype.startsWith() checks if a string starts with another string.

This refactoring replaces index-based single-character comparison with startsWidth, e.g. s[0] === '/' becomes s.startsWith('/').

What do I need to consider?

String.startsWith is an ES20215 feature. It is supported on all modern browsers, but for older browsers polyfilling might be required (browser support).

Related Code Actions

Learn More

Available In