The startsWith() method checks if a string begins with the specified string.
The startsWith() method checks if a string begins with the specified string.
It returns true if the string begins with the characters, and false otherwise.
The startsWith() method is case sensitive.
string.startsWith(searchvalue,start)
Parameter | Require | Description |
---|---|---|
searchvalue | Required. | The string to search for |
start | Optional. | Default is 0. At which position to start the search |
A Boolean type value. Returns true if the string starts with the value, otherwise it returns false
Check if a string starts with "Hello":
//check where if the string starts with the specified value. var str = "Hello world, this is a test."; var n = str.startsWith("Hello"); console.log(n);/*from w w w .ja v a 2 s . c o m*/ //Check if a string starts with "world", starting the search at position 6: var str = "world this is a test world ."; var n = str.startsWith("world", 6); console.log(n);