Today I learned the remaining string methods in JavaScript.
Yesterday, I posted on Dev Community about the string methods I had already learned.
Here is the URL of that post:
https://dev.to/laxmann/day-of-strengthening-my-dsa-fundamentals-javascript-string-methods-44b9
In that post, I covered the earlier methods.
Now Iβm sharing the methods I learned today.
Letβs start by revising the string methods:
πΉ slice()
Extracts a section of a string and returns a new string without modifying the original one.
It takes two parameters:
startIndex
endIndex
The string between these two indexes is returned.
- The startIndex is included.
- The endIndex is excluded.
πΉ split()
Converts a string into an array.
It takes two parameters:
separator
limit
The separator defines where to split the string.
The limit defines how many items you want in the resulting array.
πΉ substring()
Works similarly to slice().
It takes:
startIndex
endIndex
And returns the part of the string between those indexes.
πΉ trim()
Removes whitespace from both ends of the string.
πΉ trimEnd()
Removes whitespace from the end of the string.
πΉ trimStart()
Removes whitespace from the beginning of the string.
πΉ startsWith()
Checks whether a string starts with a given character or substring.
Returns:
true
false
πΉ toLocaleUpperCase()
Converts a string to uppercase using locale-specific case mapping.
It can take a locale as a parameter.
πΉ toUpperCase()
Converts a string to uppercase using default Unicode rules (not locale-specific).
πΉ toLowerCase() / toLocaleLowerCase()
Same concept as uppercase methods, but converts the string to lowercase.
β
What I Learned Today
Today I strengthened my understanding of:
- How string methods return new values
- The difference between slice() and substring()
- How split() works internally
The difference between locale-based and default Unicode case conversion
If you see any mistakes or have suggestions, please let me know.
I continually improve my DSA fundamentals.
Top comments (0)