# JS String Methods : Boost Your JavaScript Skills with Essential String Methods: Complete Guide

In this Blog we are going to see what useful operations we can do on strings with built-in methods, such as finding the length of a text string, joining and splitting strings, substituting one character in a string for another, and more.

## Strings Methods :

In JavaScript, string methods(🤔) are *functions that operate on strings and allow you to perform various operations and manipulations on textual data or characters.* These methods are available on string objects and are used to transform, extract, search, and modify strings. Here are some commonly used string methods in JavaScript.

(🤔): **Method** is a shorter syntax for defining a function property in an object initializer. It can also be used in [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).

## Some useful string methods:

Here are some commonly used string methods in JavaScript:

1. `length`: Returns the number of characters in a string.
    
    `const message = "Hello, World!";`
    
    `console.log(message.length);`
    
    Output: 13
    
2. `charAt()` : Returns the character at specified position.
    
    `gameName = GTA5;`
    
    `console.log(gameName.charAt(2));`
    
    Output = A
    
    Note: JavaScript indexing starts from 0.
    
3. `indexOf()`: Returns the character of that single which is at that index. `console.log(gameName.indexOf('A'));` Output = 2
    
4. `substring()`: Returns a substring from a specified string.
    
    `const newString = gameName.substring(0,2)`
    
    `console.log(newString);`
    
    Output = GTA
    
5. `slice()` : Return the substring but in slice reverse indexing (negative index number) is allowed.
    
    `anotherString = gameName.slice(-3,2);`
    
    `console.log(anotherString);`  
    Output= T
    
    `*mostly used`
    
6. `trim()` : Trims the spaces from both ends of string.
    
    `const newStringOne = " aman ";`
    
    `console.log(newStringOne);`
    
    `console.log(newStringOne.trim());`
    
    Output: ‎ `__aman__` `// (with ends spacing)`
    
    `aman` `// (without space at both ends)`
    
7. `replace()` : Replaces a specified value in string to other specified value.
    
    `const url = "https://youtu.be/fozwNn%20Funlo"console.log(url.replace('%20','-'));`
    
    Output: `https://youtu.be/fozwNn-Funlo`
    
8. `Includes()` : Returns true if the string includes the specified value otherwise false. `console.log(url.includes('foz'));`
    
    Output: `true`
    
9. `concat()`: This method is used to concatenate one or more strings together and returns a new string.
    
    `const str1 = 'Hello';`
    
    `const str2 = 'World';`
    
    `const result = str1.concat(' ', str2);`
    
    Output: `'Hello World'`
    
10. `toUpperCase()`: This method converts all characters in a string to uppercase.
    
    `const str = 'hello';`
    
    `const result = str.toUpperCase();`
    
    Output`: 'HELLO'`
    
11. `toLowerCase()`**:** This method converts all characters in a string to lowercase.
    
    `const str = 'HELLO';`
    
    `const result = str.toLowerCase();`
    
    Output: `'hello'`
    

Thanks for reading! If you enjoyed this article, consider following to my Hashnode blog account for more updates and insightful content. Feel free to leave a comment below sharing your thoughts, questions, or feedback. Let's stay connected!

Follow me on [X](https://twitter.com/huamanraj) | Connect on [LinkedIn](https://github.com/huamanraj) | Visit my [GitHub](https://github.com/huamanraj)

Copyright © 2024 Aman Raj. All rights reserved.
