DEV Community

Cover image for Basic javascript string methods and properties you should know
Oreste Abizera
Oreste Abizera

Posted on

Basic javascript string methods and properties you should know

Strings are one of the essential features found in programming. Simply they are pieces of text. I am sure that you will come across it in every programming language you might be using(if you didn't). In this article, let's look at basic javascript string methods you should know.

Let's get started:

1. String length
length property is one of the properties you will probably use in strings. It returns the length of the string.

Alt Length

2. Convert to Lowercase
toLowerCase method returns the lowercase version of the string.

Alt Text

3. Convert to Uppercase
toUpperCase method returns the uppercase version of the string.

Alt Text

4. startsWith method
startsWith method returns whether the string starts with the provided string.

Alt Text

5. endsWith method
endsWith method returns whether the string ends with the provided string.

Alt Text

6. includes method
includes method checks whether a string contains the specified string/characters.

Alt Text

7. charAt method
charAt method Returns the character at the specified index (position).

Alt Text

8. concat method
concat method joins two or more strings and returns a new joined strings.

Alt Text

9. repeat method
repeat method Returns a new string with a specified number of copies of an existing string.

Alt Text

10. slice method
slice method extracts a part of a string and returns a new string.

Alt Text

11. replace method
replace method searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced.

Alt Text

12. split method
The split method is used to split a string into an array of substrings and return the new array. If an empty string is used as the separator, the string is split between each character.

Alt Text

13. trim method
trim method removes whitespaces from both ends of the string. It does not change the original string.

Alt Text

14. substr method
substr method gets a substring beginning at the specified location and having the specified length.

Alt Text

15. substring method
substring method extracts the characters from a string, between two specified indices, and returns the new substring. It does not include the end index.

Alt Text

These are some basic string methods you should know. I promise you will need them sometime.

Did you find it helpful? You can find me on Twitter. Have a nice day!😍😍

Top comments (1)

Collapse
 
kobsharon profile image
Shallon Kobusinge

awesome.
Thanks.