The length property is a read-only property that returns the length of a string.
There will be no effect if we try to change it manually.
2️⃣ charAt(index)
This method provides the char value present at the specified index.
The charAt() method takes in the index as a parameter - An integer between 0 and "str.length - 1" and returns the char value at the specified index.
3️⃣concat()
The concat() method concatenates two or more strings and returns a new string containing the combined text of the strings provided.
If the arguments are not of the type string, they are converted to string values before concatenating.
4️⃣ replace()
The JavaScript string replace() method is used to replace a part of a given string with a new substring.
Note: The replace() method does not change the string it is called on. It simply returns a new string.
5️⃣ split()
This string method splits a string into a substring array, then returns that newly created array.
It takes in 2 parameters - pattern describing where each split should occur and the separator can be a simple string or it can be a regular expression.
6️⃣ slice(start, end)
The slice() method extracts and returns a part of the string from start to (excluding) the end.
If there's no second argument specified, then splice method goes till the end of the string.
Negative values from start/end is also possible.
7️⃣ substring(start,end)
This method is almost similar to slice().
The substring() method returns the part of a string between start and end.
It takes in 2 parameters: starting index and the ending index. Negative arguments are not supported, they're r=treated as 0.
8️⃣ substr(start, length)
This method takes in two parameters: first one is the starting index and the second parameter specifies the length of the extracted part.
9️⃣ toLowerCase()
The toLowerCase() method returns the string converted to lowercase.
🔟 toUpperCase()
The toUpperCase() method returns the string converted to uppercase.
1️⃣1️⃣ includes()
The includes() method performs a search to determine whether one string may be found within another string, returning true or false as appropriate.
1️⃣2️⃣ trim()
The trim() method removes whitespace from both sides of a string.
1️⃣3️⃣ String Padding- padStart() and padEnd()
The padStart() and padEnd() methods support padding at the beginning and at the end of a string.
It takes in the two-parameter: 1- targetLength: length of the final string 2- padString: The string to pad the current string with.
All string methods return a new string. They don't modify the original string.
In other words, Strings are immutable.
That's all for this thread!
In JavaScript, strings are of great importance and are most commonly used.
A string can represent an object as well as the primitive data type.
If you learned something new from this thread make sure to retweet it. 🔥😊
• • •
Missing some Tweet in this thread? You can try to
force a refresh
Let's deep dive into the concept of Optional Chaining in JavaScipt.
With optional chaining, we can check to see if something exists and handle an error gracefully.
A Thread 👇
What the heck is Optional chaining? 🥴
The optional chaining " ?." is a recent addition to the language which is a secure way to access nested object properties, even if an intermediate property doesn’t exist.
Optional chaining in JavaScript is very useful - we can access values without checking if the parent object exists. Instead of returning an error, it will return null or undefined.
Uberduck.AI is a tool that allows you to make any text sound like it's been read by a celebrity or fictional character, and the results are incredible.