-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringmethod.js
More file actions
51 lines (30 loc) · 1.12 KB
/
stringmethod.js
File metadata and controls
51 lines (30 loc) · 1.12 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
// string methods
let str="Welcome hello test";
console.log(str.length);// lenghth start from 1
console.log(str.toUpperCase());// convert all upper
console.log(str.toLowerCase());//convert all lower
console.log(str.charAt(10));// what value present at 10th index
console.log(str.indexOf("e")); //which index e present
console.log(str.lastIndexOf("e"));
console.log(str.includes("hello")); // check value present or not
console.log(str.startsWith("W")); // check whether this how string start
console.log(str.endsWith("st"));// check this is how string ends
console.log(str.slice(0,7));// slice the value welcome
console.log(str.slice(-10,-5)); // slice in negative
console.log(str.slice(-4)); //
console.log(str.replace("test","world")); // replace
// trim only removes space front and end
//split
let str2="Welcome hello test";
console.log(str2.split(" "));
console.log(str2.split("e"));
//task ["W","e"......."i"]
// trim method
let newstr=" hello hi "
console.log(newstr);
console.log(newstr.trim());
// concat method
console.log(str.concat(newstr)); // add of 2 strings
//task8 // str="banana"
//a==> @
// b@n@n@a