Posts.

Mastering JavaScript | 8 STRING METHODS | part 2

Cover Image for Mastering JavaScript |  8 STRING METHODS | part 2
Rami Al-Karo
Rami Al-Karo

Welcome back to our "Master JavaScript" course! In this video, we'll continue our exploration of essential JavaScript string methods. As we dive further into the world of strings, you'll gain a deeper understanding of how to effectively manipulate and transform text data.

Let's pick up, where we left off and cover more string methods.

The trim() method allow to remove any leading and trailing whitespace characters from a string:

1const text = " Hello, World! "; 2const trimmedText = text.trim(); 3console.log(trimmedText); // Output: "Hello, World!"

if want to remove whitespace characters from leading then use thetrimStart() method, while the trimEnd() method do the opposite and remove the whitespace characters from trailing:

1const text = " Hello, World! "; 2const trimmedStart = text.trimStart(); 3console.log(trimmedStart); // Output: "Hello, World! " 4const trimmedEnd = text.trimEnd(); 5console.log(trimmedEnd); // Output: " Hello, World!"

if the target was to add padding to the text then use the padStart() and padEnd() methods allow you to add padding to the beginning or end of a string until it reaches a specified length:

1const originalText = "Hello" 2const paddedStart = originalText.padStart(10, "*"); 3console.log(paddedStart); // Output: "*****Hello" 4const paddedEnd = originalText.padEnd(10, "*"); 5console.log(paddedEnd); // Output: "Hello*****"

With the charAt() method, you can retrieve the character at a specific index within a string:

1const text = "Hello, World!"; 2const char = text.charAt(7); 3console.log(char); // Output: "W"

Similar to charAt(), the charCodeAt() method returns the Unicode value of the character at a given index:

1const text = "Hello, World!"; 2const unicodeValue = text.charCodeAt(0); 3console.log(unicodeValue); // Output: 72 (Unicode value of "H")

final method for this video is the split() method divides a string into an array of substrings based on a specified delimiter:

1const text = "apple,banana,kiwi"; 2const fruitsArray = text.split(","); 3console.log(fruitsArray); // Output: ["apple", "banana", "kiwi"]

Congratulations, you've now expanded your arsenal of JavaScript string methods! If you found this video helpful, remember to give it a thumbs up and stay tuned for more content. Happy coding, and see you in the next segment!


More Stories

Cover Image for  5 Array Methods in JavaScript | Part 3 | Mastering JavaScript

5 Array Methods in JavaScript | Part 3 | Mastering JavaScript

485 words - 2,754 characters

Rami Al-Karo
Rami Al-Karo
Cover Image for 5 Array Methods | Part 2 | Mastering JavaScript

5 Array Methods | Part 2 | Mastering JavaScript

907 words - 5,716 characters

Rami Al-Karo
Rami Al-Karo