-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.js
More file actions
32 lines (27 loc) · 946 Bytes
/
string.js
File metadata and controls
32 lines (27 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
let str="helloWorld"
let anotherStr=new String("goodMorning") //another way to define string
console.log(anotherStr)
let url="hello-world-to-friends@yahoo.org"
/* there are so many funstion one can perform on strings such as :
-length
-toLowerCase()
-toUpperCase()
-charAt(index)
-indexOf(character)
-trim()
-replace()
-includes()
-split()
-substring()
-slice()
*/
console.log(str.length)
console.log(str.toUpperCase())
console.log(str.toLowerCase())
console.log(anotherStr.indexOf('r'))
console.log(anotherStr.charAt(3))
console.log(str.substring(0,4))
console.log(anotherStr.slice(2,5))
console.log(anotherStr.replace("rni","30")) // replaces rni in anotherStr to 30
console.log(anotherStr.includes("key")) //checks wether "key" exist in anotherStr or not
console.log(url.split("-")) // used to divide the string when "-" encountered