New String Methods
built-in Javascript methods to parse strings and analyze them, along with examples
We'll cover the following
Some popular checks that can be done with regular expressions are now possible in a more semantic way. Here are some functions that we can use:
Function Name | Syntax | Output |
---|---|---|
startsWith |
s1.startsWith(s2) |
true if and only if s1 starts with s2 |
endsWith |
s1.endsWith(s2) |
true if and only if s1 ends with s2 |
includes : |
s1.includes(s2) |
true if and only if s2 is a substring of s1 |
repeat |
s.repeat(n) |
replicates s n times, and joins them |
Examples:
Get hands-on with 1400+ tech skills courses.