YouTip LogoYouTip

Jsref Startswith

body { font-family: Arial, sans-serif; line-height: 1.6; margin: 20px; } h1, h2, h3 { color: #333; } table { border-collapse: collapse; width: 100%; margin: 20px 0; } th, td { border: 1px solid #ddd; padding: 8px; text-align: left; } th { background-color: #f2f2f2; } code { background-color: #f4f4f4; padding: 2px 5px; border-radius: 3px; font-family: monospace; } pre { background-color: #f4f4f4; padding: 10px; border-radius: 5px; overflow-x: auto; } .example { margin: 20px 0; padding: 15px; border-left: 4px solid #007bff; background-color: #f8f9fa; } .note { font-style: italic; color: #666; } a { color: #007bff; text-decoration: none; } a:hover { text-decoration: underline; } .nav { margin-bottom: 30px; } .nav a { margin-right: 15px; }

JavaScript startsWith() Method | Tutorial

JavaScript Reference

Overview - JavaScript and HTML DOM Reference

JavaScript Objects

Browser Objects

DOM Objects


JavaScript startsWith() Method

JavaScript String Object Reference

Example

Check if a string starts with "Hello":

var str = "Hello world, welcome to the Tutorial.";
var n = str.startsWith("Hello");

n output:

true

Try it yourself Β»


Definition and Usage

The startsWith() method is used to check whether a string begins with a specified substring.

It returns true if the string starts with the specified substring, otherwise false.

The startsWith() method is case-sensitive.


Browser Support

The numbers in the table specify the first browser version that fully supports the method.

Method Chrome Edge Firefox Safari Opera
startsWith() 41 12.0 17 9 28

Syntax

string.startsWith(searchvalue, start)

Parameter Values

Parameter Description
searchvalue Required. The string to search for.
start Optional. The position in the string to start the search. Default is 0.

Return Value

Type Description
Boolean Returns true if the string starts with the specified substring, otherwise false.

Technical Details

JavaScript Version: ECMAScript 6

More Examples

Check if a string starts with "world" from index position 6:

var str = "Hello world, welcome to the Tutorial.";
var n = str.startsWith("world", 6);

n output:

true

Try it yourself Β»


JavaScript String Object Reference

← Linux Comm E2FsckObj Wrapper β†’