Unleash the Power of JavaScript String Methods - Your Ultimate Cheat Sheet 🀯πŸ”₯

Ram Maheshwari ♾️ - Feb 1 '23 - - Dev Community

JavaScript strings are a powerful tool for manipulating text and working with data. To get the most out of your strings, you'll want to familiarize yourself with the various string methods available in JavaScript πŸ”₯

In this article, I'll provide you with an ultimate cheat sheet for JavaScript string methods, making it easy to find exactly what you need to accomplish your goals πŸš€

With clear code examples and descriptions, you'll learn how to use each method to perform common string operations like finding substrings, converting case, and removing whitespace 😎

Whether you're a seasoned JavaScript developer or just starting out, this cheat sheet will be a valuable resource for optimizing your string-based code ⚑

So, Let's get started πŸ€–


1) str.length : returns the length of a string.

JS str.length example


2) str.charAt(index) : returns the character at the specified index in a string.

JS str.charAT(index) example


3) str.indexOf(searchValue[, fromIndex]) : returns the index of the first occurrence of the specified value in a string.

JS str.indexOf(searchValue[, fromIndex] example


4) str.lastIndexOf(searchValue[, fromIndex]) : returns the index of the last occurrence of the specified value in a string.

JS str.lastIndexOf(searchValue[, fromIndex] example


5) str.substring(start[, end]) : returns a new string that is a substring of the original string.

JS substring(start[, end]) example


6) str.substr(start[, length]) : returns a new string that is a part of the original string.

JS str.substr(start[, length]) example


7) str.toLowerCase() : returns a new string with all characters in lower case.

JS str.toLowerCase() example


8) str.toUpperCase() : returns a new string with all characters in upper case.

JS str.toUpperCase() example


9) str.trim() : removes whitespace from both ends of a string

JS str.trim() example


10) str.replace(searchValue, replaceValue) : replaces all occurrences of the specified value in a string with another value.

JS str.replace(searchValue, replaceValue) example


Hope this is helpful ✨

Do Like ❀️ & Save πŸ”–


Do π—™π—Όπ—Ήπ—Ήπ—Όπ˜„ me on Linkedin for more:
TipsπŸ’‘+ GuidesπŸ“œ + Resources ⚑ related to Programming and Web Development πŸ‘¨β€πŸ’»

Ram Maheshwari (@rammcodes) Linkedin


Do Follow me here on dev.to βœ…

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player