Top 20
JavaScript
String Methods
Everyone Must
Know
@avinashsah995
.length
What it does: Returns the length
of a string.
Use case: When you need to
know how many characters are
in a string.
@avinashsah995
.toUpperCase()
What it does: Converts a string
to uppercase letters.
Use case: When you need to
standardize text to uppercase.
@avinashsah995
.toLowerCase()
What it does: Converts a string
to lowercase letters.
Use case: When you need to
standardize text to lowercase.
@avinashsah995
.charAt()
What it does: Returns the
character at a specified index.
Use case: When you need to
access a specific character in a
string.
@avinashsah995
.charCodeAt()
What it does: Returns the
Unicode of the character at a
specified index.
Use case: When you need to get
the ASCII/Unicode value of a
character.
@avinashsah995
.concat()
What it does: Joins two or more
strings together.
Use case: When you need to
combine strings dynamically.
@avinashsah995
.includes()
What it does: Checks if a string
contains a specific substring.
Use case: When you need to
verify the presence of a word in
a string.
@avinashsah995
.indexOf()
What it does: Returns the index
of the first occurrence of a
substring.
Use case: When you need to find
where a specific word starts.
@avinashsah995
.lastIndexOf()
What it does: Returns the index
of the last occurrence of a
substring.
Use case: When you need to find
the last position of a word.
@avinashsah995
.slice()
What it does: Extracts a section
of a string and returns a new
string.
Use case: When you need to get
part of a string.
@avinashsah995
.substring()
What it does: Similar to .slice(),
but doesn't accept negative
indexes.
Use case: When you need to
extract part of a string safely.
@avinashsah995
.substr()
What it does: Extracts a
substring based on a starting
index and length.
Use case: When you need to get
a substring of a specific length.
@avinashsah995
.replace()
What it does: Replaces a
substring with another string.
Use case: When you need to
modify part of a string.
@avinashsah995
.replaceAll()
What it does: Replaces all
occurrences of a substring.
Use case: When you need to
replace multiple instances of a
word.
@avinashsah995
.split()
What it does: Splits a string into
an array based on a delimiter.
Use case: When you need to
break a string into parts.
@avinashsah995
.trim()
What it does: Removes
whitespace from both ends of a
string.
Use case: When you need to
clean up user input.
@avinashsah995
.trimStart()
What it does: Removes
whitespace from the start of a
string.
Use case: When you need to
remove spaces from the
beginning only.
@avinashsah995
.trimEnd()
What it does: Removes
whitespace from the end of a
string.
Use case: When you need to
remove spaces from the end
only.
@avinashsah995
.padStart()
What it does: Pads the start of a
string with a specified character.
Use case: When you need to
format numbers with leading
zeros.
@avinashsah995
.padEnd()
What it does: Pads the end of a
string with a specified character.
Use case: When you need to
format text output.
@avinashsah995
Hopefully You
Found It Usefull!
Be sure to save this post so you
can come back to it later
Like 👍
Comment 💬
Share ❤️
@avinashsah995