JavaScript String Methods - What are string methods in Javascript
JavaScript String Methods
- String length
- String slice()
- String substring()
- String substr()
- String replace()
- String replaceAll()
- String toUpperCase()
- String toLowerCase()
- String concat()
- String trim()
- String trimStart()
- String trimEnd()
- String padStart()
- String padEnd()
- String charAt()
- String charCodeAt()
- String split()
JavaScript String Length Method
- In JavaScript, you can find the length of a string by using the .length property.
- The .length property is used to find the length of the text variable, which contains the string "ABCDEFGHIJKLMNOPQRSTUVWXYZ". The output will be 26, which is the number of characters in the string.
Sample Code
Output
JavaScript Slice Method Example 1
- In JavaScript, the slice() method is used to extract a portion of a string, array or typed array, and return a new array or string without modifying the original one.
- The slice() method takes two parameters: start and end. The start parameter specifies the starting index of the slice (inclusive), and the end parameter specifies the ending index of the slice (exclusive).
Sample Code
Output
JavaScript Slice Method Example 2
Sample Code
Output
JavaScript String substring() Method
- substring() is almost equalto slice().
- The difference is that start and end values less than 0 are treated as 0 in substring().