Method StarWith javascript
The startsWith() method in JavaScript is used to determine whether a string starts with a specified substring or not. It returns a boolean value (true or false).
Syntax:
string.startsWith(searchString, position)
Parameters:
searchString: It is the string or character which we want to search for in the given string.
position (optional): It is an integer value which specifies the position within the string to start the search.
Returns:
This method returns a boolean value (true or false). If the given string starts with the specified substring, it will return true. Otherwise, it will return false.
Example:
let str = "Hello World";
console.log(str.startsWith("Hello")); // true console.log(str.startsWith("world")); // false console.log(str.startsWith("World", 6)); // true (search starts from position 6
原文地址: https://www.cveoy.top/t/topic/g5ix 著作权归作者所有。请勿转载和采集!