To determine if a string begins with another string in JavaScript , use the startsWith() method:
let str = "Hello, world!";
let result = str.startsWith("Hello"); // true
Use string.startsWith(substring)
to check if a string begins with another string. It returns true
or false
.