String
String
1. toLowerCase()
2 . toUpperCase()
3. includes()
4. startsWith()
5. endsWith()
7. indexOf()
8. lastIndexOf()
9. concat()
10. split()
12. trimStart()
13. trimEnd()
14. slice()
The slice() method extracts a part of a string and returns it as a new string,
without modifying the original string.
# Syntax
string.slice(startIndex, endIndex)
# Syntax
string.substring(start, end)
Key Differences
2. **Parameter Swapping**:
- substring(start, end): Swaps the two arguments if start is greater
than end.
- slice(start, end) and substr(start, length): Do not swap the
arguments.
16. replace()
17. replaceAll()
this method is used to return a new string with all matches of a pattern
replaced by a replacement
// ! declaration of String
// ! 2. by using object
console.log(str1)
console.log(strObj1)
console.log(str1.length)
// ! 1. toUpperCase()
console.log(str4); // hello
console.log(upper) //HELLO
//! 2. toLowerCase()
console.log(str5) // HELLO
console.log(lower) // hello
//! 3. charAt()
console.log(str6.charAt(2)) // l
// ! 4. indexOf()
console.log(str6.indexOf('l')) // 2
// ! 5. lastIndexOf()
console.log(str6.lastIndexOf('l')) // 18
// ! 6. concat()
// ! 7. trim()
// ! 8. trimStart()
// ! 9. trimEnd()
// ! 10. includes()
// ! 12. endsWith()
console.log(str11.endsWith('un'))
// ! 13. split()
// ! 15. substring()
console.log(str12.substring(1,7))
console.log(str12.substring(1))
console.log(str12.substring(-8)) // it will convert -8 to 0
console.log(str12.substring(6,1)) // ello (it will swap 6,1 to 1,6)
// ! String Interpolation