-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmethods.js
More file actions
58 lines (44 loc) · 2.13 KB
/
Copy pathmethods.js
File metadata and controls
58 lines (44 loc) · 2.13 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
let text = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let length = text.length; // return length of a string
console.log("String Length :", length);
console.log(text.at(3)); // returns the character at a specified index in a string
console.log(text.charAt(3)); // returns the character at a specified index in a string
console.log(text[3]); // returns the character at a specified index in a string
console.log(text.charCodeAt(3)); // returns a UTF-16 code between 0 and 65535
console.log(text.codePointAt(3)); // retuen code point value
console.log("My name is" + " " + "Partha Sarker");
let firstName = "Partha"
let lastName = "sarker"
let age = 23
console.log("My name is "+ firstName.concat(" ",lastName, " ", "And i am", " " ,age , " ", "years old" ));
// Extracting string parts
let text2 = "Javascript Programming"
// JavaScript counts positions from zero.
console.log(text2.slice(0,10)); // return Javascript
console.log(text2.slice(0,4)); // return Java
console.log(text2.slice(4,10)); // return script
// omit the second parameter slice(11) => start sliceing form index 11 to end
console.log(text2.slice(11)); // return Programming
console.log(text2.slice(-11)); // return Programming, now position is counted from the end of the string
console.log(text2.slice(11 , -4)); // return Program
console.log([].splice(0));
console.log(text2.substring(0,10)); // start and end values must less than 0
// Converting to upper and lower case
console.log(text2.toLowerCase());
console.log(text2.toUpperCase());
console.log(text2.isWellFormed());
let text3 = " Hello World!";
console.log(text3.trim());
// Javascript string repeat() mathod
let text4 = "hi ";
console.log(text4.repeat(4)); // return hi hi hi hi
// Replacing string content
let text5 = "I am an doctor"
console.log(text5.replace("doctor", "engineer"));
// By default the replace() method is case sensitive and replaces only the first
// To replace case insensitive or global match use a regular expression with /i or /g flag
// JavaScript string split()
let text6 = "My name is partha sarker,I am 23 years old."
console.log(text6.split(","));
console.log(text6.split(" "));
console.log(text6.split("."));