-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtut50.html
More file actions
48 lines (39 loc) · 1.33 KB
/
tut50.html
File metadata and controls
48 lines (39 loc) · 1.33 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScript String Functions</title>
<style>
</style>
</head>
<body>
<script>
var str = 'This is a string';
console.log(str);
// first occurence of a substring
var position = str.indexOf('is');
position = str.lastIndexOf('is');
console.log(position);
// Substring from a string
// var substr = str.slice(1,7); // index 1 to 7
// var substr = str.substring(1,7);//index 1 to 7
var substr1 = str.substr(1, 3); //from 1 to length 3
console.log(substr1)
// var replaced = str.replace('string', 'Harry');
// console.log(str)
// console.log(replaced)
// console.log(str.toUpperCase());
// console.log(str.toLowerCase());
// var newString = str.concat('New String')
// console.log(newString)
// var strWithWhitespaces = " this contains whitespaces ";
// console.log(strWithWhitespaces)
// console.log(strWithWhitespaces.trim())
// var char2 = str.charAt(2);
// var char2 = str.charCodeAt(2); // Not very important
// console.log(char2)
console.log(str[3])
</script>
</body>
</html>