-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9-stringFunctions.html
60 lines (41 loc) · 1.34 KB
/
9-stringFunctions.html
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>string functions</title>
</head>
<body>
<script>
//1) indexof();
//give the first substring
let str = " this is javaScript course ";
position = str.indexOf("is");
console.log(position);
//2) lastindexof();
lastindex = str.lastIndexOf("is");
console.log(lastindex);
//3) .slice() , .substring();
// both are extrect substrings
//major difference is .slice() method takes negative values also.
var slice = str.slice(1, 7);
console.log(slice);
//4) .replace();
var replacesubstring = str.replace("javaScript", "python");
console.log(replacesubstring);
//5) toupparcase(); , tolowercase();
var upparCase = str.toUpperCase();
console.log(upparCase);
var lowerCase = str.toLowerCase();
console.log(lowerCase);
//6) .concate();
//concatenate the string
var concatenate = str.concat("javaScript", "course");
console.log(concatenate);
//7) .trim();
var totrim = str.trim();
console.log(totrim);
</script>
</body>
</html>