8 Useful JavaScript String Methods

Subscribe to my newsletter and never miss my upcoming articles

A JavaScript string stores a series of characters like "Rahul". String indexes are zero-based: The first character is in position 0, the second in 1, and so on. So here in the post, we're gonna see some of these useful string methods you can use for your projects to save your time and increase your productivity.

Let's Start 🤘🙌

1. indexOf

The indexOf() method returns the index of (the position of) the first occurrence of a specified text. ```javascript const str ='I have Css, Wait I love CSS' str.indexOf('Css');

// 7

### 2. length

> The `length` property returns the length of a string. 

const str = 'ILoveCss'

// 8

3. slice

slice() extracts a part of a string and returns the extracted part in a new string.

const str = 'ILoveCss';

// ove

4. replace

The replace() method replaces a specified value with another value in a string.

const str = 'IHateCss';
str.replace('Hate', 'Love');


5. upper and lower case

This method converts a string to lowercase or uppercase

const str="ILoveCss";
// ilovecss


6. trim

The trim() methods removes whitespace from both sides of the string

const str = '        ILoveCss'      ;

// ILoveCss

7. concat

concat() joins two or more strings. The concat() method can be used instead of the plus operator

const str = 'Ilove';

// ILoveCss

8. split

A string can ve converted to an array with the split() method

const str = 'I,Love,Css'; 

// ['I', 'Love', 'Css']

Thanks For Reading. 🙂
Hope you like the content.
And plz surely comment if you want to add something to this. 🙌😎

No Comments Yet