17+ JavaScript String methods Explained
This is what you need to know about strings.
From your name to your Ethereum wallet address, everything is a string. This comprehensive blog will teach you all of the essential JavaScript String methods.
So let’s get started!
So what is a String?
A string is a sequence of characters, usually used to represent text. In programming, strings are a data type used to store and manipulate text-based information, such as words, phrases, and sentences.
Strings Methods
A string method is a pre-defined function that can be used on strings in many programming languages.
String Length
The length property returns the length of a string:
String substring()
substring() is similar to slice().
The difference is that substring() cannot accept negative indexes.
String slice()
slice() extracts a part of a string and returns the extracted part in a new string.
String replace()
The replace() method replaces a specified value with another value in a string:
String concat()
The concat() method can be used instead of the plus operator. These two lines do the same:
String trim()
The trim() method removes whitespace from both sides of a string:
Property Access
ECMAScript 5 (2009) allows property access [ ] on strings:
String includes()
The includes() method determines whether a string contains the characters of a specified string.
String charAt()
The charAt() method returns the character at a specified index (position) in a string:
Upper and Lower Case
A string is converted to upper case with toUpperCase():
A string is converted to lower case with toLowerCase():
String split()
A string can be converted to an array with the split() method:
String repeat()
The repeat() method returns a new string with a
specified number of copies of the string it was
called on.
Wrapping it up
Whether you’re a beginner or an experienced developer, taking the time to master the fundamentals of JavaScript will pay off in the long run. Thanks for reading, and happy coding.
If you want to learn about CSS FlexBox in-depth, check this Ebook