-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJS4.html
More file actions
64 lines (47 loc) · 1.91 KB
/
JS4.html
File metadata and controls
64 lines (47 loc) · 1.91 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScript String Function</title>
</head>
<body>
<script>
// this is a normal string
var str = 'This is a String';
console.log(str);
// Getting position of the string
// first occurence of a sub string
var position = str.indexOf('is');
console.log(position);
// Getting position of the string
// first occurence of a sub string
// Index always strat with 0
position = str.lastIndexOf('is');
console.log(position);
// substring from a string
// var substr = str.slice(1,6);
// var substr = str.substring(1,6);
var substr1 = str.substr(1,6);
// the substr is the starting fetch point but the 2 vlaue is for limit
console.log(substr1);
// if we want to replace a substring with a string like in first code there was written as this is a string i want to repace the string my name harsh
// var replaced = str.replace('string', 'Harsh');
// console.log(str);
// console.log(replaced);
console.log(str.toUpperCase())
console.log(str.toLowerCase())
// this is as same a how we add strings using + here we are using concat syntax to do so
var newString = str.concat('New String');
console.log(newString)
var strWithWhiteSpaces = ' this is a str with white spaces';
console.log(strWithWhiteSpaces)
console.log(strWithWhiteSpaces.trim())
// Now to check the character of the string by using the numbers like slice or substr
// var char3 = str.charAt(2)
// this charcodeat gives you the charcter code
var char3 = str.charCodeAt(2)
console.log(char3)
</script>
</body>
</html>