Search
The startsWith() method returns true if a string starts with the given substring and returns false otherwise.
startsWith()
true
false
In the example given above, "Sam loves mangoes." starts with the substring "Sam: ", hence message.startsWith("Sam: ") returns true.
"Sam loves mangoes."
"Sam: "
message.startsWith("Sam: ")