1var str = "Hello world, welcome to the universe.";
2var n = str.startsWith("Hello");
1var str = "Hello world, welcome to the universe.";
2var n = str.startsWith("Hello");//true
1const str = "Saturday night plans";
2const res = str.startsWith("Sat");
3console.log(res); //> true
1//checks if a string starts with a word
2function startsWith(str, word) {
3 return str.lastIndexOf(word, 0) === 0;
4}
5startsWith("Welcome to earth.","Welcome"); //true