0 ratings0% found this document useful (0 votes) 44 views3 pagesString
its basically for java Script
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
0
ua
B
oT
6
16
v
@
a
a
B
B
6
{String handbook
{/ String: length, indexof(), lastundexof(), slice(), substring(), replace(),
J] split(), trim(), toppercase(), toLowerCase(), etc.
JJ Run each function to see the output, play and learn by doing.
ff Length
function getLength(str) {
console. log(*Original string:", str);
console. log("Length:", str. length)
}
getLength( "Hello World");
1] indexof
function Findindexof(str, target) {
console. log(*Original string:", str);
console. log("Index:", str. indexof(target));
}
indIndexof("Hello World”, "world”);
1] lastIindexof
function FindLastIndexof(str, target) {
console. log(*Original string:", str);
console. log("Index:", str. lastindexcf(target));
}a
2B
2
30
31
32
3B
3
35
36
7
38
39
aL
a
45
a7
49
findLastIndexof("Hello World World", “world");
I/ slice
function getSlice(str, start, end) {
", str);
console. log("after slice:", str.slice(start, end))3
}
getSlice("Hello World", @, 5)
console. log("original strin
J/ substring
function getSubstring(str, start, end) {
", ste);
console. log("after substring:", str.substring(start, end));
}
getSubstring("Hello World”, @, 5)3
console. log("Original strin
I/ replace
function replacestring(str, target, replacenent) {
» str);
console. log("after replace:", str.replace(target, replacenent));
}
replacestring("Hello World", "World", "JavaScript");
console. log("Original string50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
6
66
or
68
6
7
72
rz
7A
75
76
7 split
function splitstring(str, separator) {
console, log("original string:", str);
console. log(*After split:", str.split(separator));
+
splitstring("Hello World", ““);
f/ trim
function trimstring(ste) {
console. log(“Original string:", str);
console.log(“after trim:", str.trim());
}
trimstring(" Hello world *);
11 touppercase
function toupper(str) {
console, log("original string:", str);
console. log(*AFter toUppercase:", str. toUppercase())s
+
tovpper(“Hello World”);
// toLowercase
function toLower(str) {
console. log("Original String:", str);
console. log("after toLowercase:", str.toLowercase());
i
toLower("Hello World");