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.
2) str.charAt(index)
: returns the character at the specified index in a string.
3) str.indexOf(searchValue[, fromIndex])
: returns the index of the first occurrence of the specified value in a string.
4) str.lastIndexOf(searchValue[, fromIndex])
: returns the index of the last occurrence of the specified value in a string.
5) str.substring(start[, end])
: returns a new string that is a substring of the original string.
6) str.substr(start[, length])
: returns a new string that is a part of the original string.
7) str.toLowerCase()
: returns a new string with all characters in lower case.
8) str.toUpperCase()
: returns a new string with all characters in upper case.
9) str.trim()
: removes whitespace from both ends of a string
10) str.replace(searchValue, replaceValue)
: replaces all occurrences of the specified value in a string with another value.
Hope this is helpful β¨
Do Like β€οΈ & Save π
Do ππΌπΉπΉπΌπ me on Linkedin for more:
Tipsπ‘+ Guidesπ + Resources β‘ related to Programming and Web Development π¨βπ»
Do Follow me here on dev.to β