Use string.startsWith()

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

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).

Configuration

Related Code Assists

Learn More

Available In