-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05_string.js
More file actions
57 lines (38 loc) · 1.68 KB
/
Copy path05_string.js
File metadata and controls
57 lines (38 loc) · 1.68 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
const name="raj" //This is typeof string
const repo=30
console.log(`Hello My name is ${name} and i have ${repo}+ repositories`);
const user=new String("Samuel"); // This String typeof is object.
console.log(user[0]);
console.log(user.length) //6 will be the output.
//Methods
console.log(user.toUpperCase()); //ToUppercase
console.log(user.charAt(3)); //ToL
console.log(user.indexOf('m'));
let userTwo="Shekhar-Raj"
//Substring Method(start,end);
const newString=userTwo.substring(0,4);
const trial=userTwo.substring(-10,2) // we cannot give negative values to the substring.
console.log(newString);
console.log(trial);
//Slice --> returns a aprt of original string as a new string
const slice=userTwo.slice(-11,4);
console.log(slice)
//Trim --> trims whitespaces from both ends of string & return a new one
let msg=" Hello "
msg.trim();
//replace --> searches a value in the string and return a new string with value replaced.
let url="https://shekhar.com/shekhar%20raj"
console.log(url.replace("%20","-"));
//includes --> to to confirm whether a particular string is present or not
console.log(url.includes("raj"));
//split-->
//The split() method of String values takes a pattern and divides this string into an ordered list of substrings by searching for the pattern,
//puts these substrings into an array, and returns the array.
const str1='The quick brown fox jumps over the lazy dog.';
const words=str1.split(' ') //split on the space
console.log(words[3]);
const chars=str1.split('') //splits the string on every letter
console.log(chars);
const strCopy=str1.split() // Converts the sring into array
console.log(strCopy);
// console.log(user.__proto__) ]