You can use the substr
method to get the first word from a string and then use the toLowerCase
method to convert it to lowercase.
Here's an example code snippet:
index.tsx144 chars4 lines
In the code above, we first declare a variable string
which contains the input string. We then use substr
to extract the first word from the string, starting from index 0 and ending at the position of the first space character in the string (using indexOf
method).
Finally, we apply toLowerCase
method to convert the first word to lowercase and assign the result to the firstWord
variable. The output is then logged to the console.
gistlibby LogSnag