- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path21_string_properties_method.js
More file actions
Latest commit
48 lines (43 loc) · 1.57 KB
/
Copy path21_string_properties_method.js
File metadata and controls
48 lines (43 loc) · 1.57 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
// String properties and methods
// wrapper string object
lettext='John Doe';
letresult=text;
console.log(result.length);//8
console.log(result[0]);//J
console.log(result[4]);//Blank space
// Lower & upper
console.log(result.toLowerCase());//john doe
console.log(result.toUpperCase());//JOHN DOE
// search target string
console.log(result.includes('ohn'));//true
console.log(result.includes('not'));//false
// startsWith, end with
console.log(result.startsWith('John'));//true
console.log(result.startsWith('john'));//false
console.log(result.endsWith('e'));//true
// change string
console.log(result.replace('John','Peter'));
console.log(result.indexOf('Doe'));// 5
console.log(result.indexOf('oe'));//6
console.log(result.charAt(0));//J
console.log(result.charAt(result.length-1));//e
// trim for remove space
letname=' dncode';
console.log(name);
console.log(name.trim());
console.log(name.trim().toUpperCase().startsWith('DNCODE'));//true
console.log('slice');
name='john jordan';
// slice if 0 is first index
console.log(name);
console.log(name.slice(-1));//n
console.log(name.slice(-2));//an
console.log(name.slice(1));//ohn jordan
console.log(name.slice(0));//john jordan
console.log(name.slice(0,7));//start 0 index, end 7 word..
name='Nakamura Ekuichi';//totally word and space is calculate too
console.log(name.length);
console.log(name.slice(9,name.length));
console.log(name.slice(0,10));//0 is index, and 10 is stopping for last word and the lasts word is E.
// here start -12 mura Ekuichi, and stopp on E for -6
console.log(name.slice(-12,-6));