Unleash the Power of JavaScript String Methods - Your Ultimate Cheat Sheet 🤯🔥
Tags: javascript, webdev, react, html
Published: 2023-02-01 09:55:41

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/faf8ahymw11p4buqwrx6.png)

---

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

![JS str.charAT(index) example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nfad416ln7w2pxzwxv7g.png)

---

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gtlul8rtz9773u81nwx6.png)

---

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zfbe1yt0q1h7ya789m8h.png)

---

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

![JS substring(start[, end]) example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ts27szae9ln1zcw3mgah.png)

---

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

![JS str.substr(start[, length]) example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mn4w91cmwx6y1hnwc6zj.png)

---

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

![JS str.toLowerCase() example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/na1owzuln34gq2d3rqvv.png)

---

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

![JS str.toUpperCase() example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hhf5mf3wolqa8ahgy4hw.png)

---

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

![JS str.trim() example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xlm2hxzo1vmf6uzq78tn.png)

---

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

![JS str.replace(searchValue, replaceValue) example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ujkrhd9kgpd2yd3n00pj.png)

---

Hope this is helpful ✨

Do Like ❤️ & Save 🔖

---

Do 𝗙𝗼𝗹𝗹𝗼𝘄 me on **[Linkedin](https://Linkedin.com/in/rammcodes)** for more:
Tips💡+ Guides📜 + Resources ⚡ related to Programming and Web Development 👨‍💻

[![Ram Maheshwari (@rammcodes) Linkedin](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wlsfmflqibz3yam59jkk.png)](https://linkedin.com/in/rammcodes)

---

Do **Follow** me here on dev.to ✅