-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs-string.js
41 lines (30 loc) · 931 Bytes
/
js-string.js
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
//String
console.log("Hello World!");
let email = "[email protected]";
console.log(email);
let myAge = 30;
//string concatenation
let firstName = "Chang";
let lastName = "Wonderland";
let fullName = firstName + " " + lastName;
console.log(fullName);
let info = `My name is ${fullName}`;
console.log(info);
//getting character
console.log(fullName[0]);
//string length
console.log(fullName.length);
//string methods - this method will not change the original variable length
console.log(fullName.toUpperCase());
let result = fullName.toLowerCase();
console.log(result);
console.log(fullName);
//find index in the string
let index = email.indexOf("@"); //find the index of @ in email
console.log(index);
//find the last index of the last letter defind
let findLastIndex = email.lastIndexOf("o"); //
console.log(findLastIndex);
//slice the string (from,to)
let slice = email.slice(3, 10);
console.log(slice);