Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 388114f

Browse files
learned how i can use split()includes()startsWith()endsWith()concat()repeat()trim()trimStart()trimEnd()padStart()padEnd() methods
1 parent 5f55232 commit 388114f

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

‎String methods/script.js

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,114 @@
4040
// console.log(s.substring(-8,4));//first negative number change to zero
4141
// console.log(s.slice(8,-4));
4242
// console.log(s.substring(8,-4));//first negative number change to zero than compare numbers if endIndex is less than indexStart than swapped their place
43+
44+
45+
// SPLIT() MEHTOD //
46+
47+
//SYNTAXES
48+
//string.split()
49+
//string.split(separator)
50+
//string.split(separator,limit)
51+
52+
// const string = 'The morning is upon us';
53+
// const arr0 = string.split()//[ 'The morning is upon us' ]
54+
// const arr1 = string.split(' ')//[ 'The', 'morning', 'is', 'upon', 'us' ]
55+
// const arr2 = string.split('')[
56+
// 'T', 'h', 'e', ' ', 'm',
57+
// 'o', 'r', 'n', 'i', 'n',
58+
// 'g', ' ', 'i', 's', ' ',
59+
// 'u', 'p', 'o', 'n', ' ',
60+
// 'u', 's'
61+
// ]
62+
// const arr3 = string.split('o')//[ 'The m', 'rning is up', 'n us' ]
63+
// const arr5 = string.split('o',2)//[ 'The m', 'rning is up' ]
64+
// const arr6 = string.split('o',0)// [] empty array
65+
// console.log(arr0);
66+
// console.log(arr1);
67+
// console.log(arr2);
68+
// console.log(arr3);
69+
// console.log(arr5);
70+
// console.log(arr6);
71+
72+
// INCLUDES() METHOD
73+
74+
//SYNTAXES
75+
//string.includes(searchString)
76+
//string.includes(searchString,position)
77+
// const str = 'The quick brown fox running very fast than rabbit';
78+
// console.log(str.includes('rabbit'));//it returns true becuse it is checking this string is include or not
79+
// console.log(str.includes('fox',0));//there start searching from position zero
80+
81+
82+
// STARTSWITH()
83+
//SYNTAXES
84+
// string.startsWith(searchString);
85+
//string.startsWith(searchString,Position);
86+
// it is sensetive
87+
88+
// const str = 'Cats are the best ';
89+
// console.log(str.startsWith('Cate'));
90+
// console.log(str.startsWith('Cats',5));
91+
92+
//ENDSWITH() METHOD
93+
// SYNTAXES
94+
// string.endsWith(searchString);
95+
// string.endsWith(searchString,length)
96+
97+
// const str = 'The cats are best!'
98+
// console.log(str.endsWith('best'));
99+
// console.log(str.endsWith('best',17));
100+
101+
102+
// CONCAT() METHOD //
103+
104+
// SYNTAXES
105+
// str1.concat(str2)
106+
//str1.concat(str2,str3,...,str5)
107+
108+
// const str = 'hello';
109+
// const str1 = 'World';
110+
// const str3 = 'I am';
111+
// const str4 = 'Turabek Yusubov'
112+
// console.log(str.concat(' ',str1,',',str3,' ',str4));
113+
114+
// REPEAT() METHOD
115+
116+
// SYNTAXES
117+
// string.repeat(count)
118+
119+
// const str = 'abc'
120+
// console.log(str.repeat(0));//empty string
121+
// console.log(str.repeat(1));
122+
// console.log(str.repeat(3.5));// method will change integer this count number "3.5";
123+
// console.log(str.repeat(-1));// it returns 'Range error'
124+
// console.log(str.repeat(1/0));//it returns "Range Error"
125+
126+
127+
// TRIMSTART() - TRIM() - TRIMEND() //
128+
//SYNTAXES
129+
// string.trimStart() - string.trim() - string.trimEnd() //
130+
131+
// const s = ' Hello world '
132+
// const str = s.trimStart()// remove space from start till index position
133+
// const str1 = s.trim()// remove space from both sides
134+
// const str2 = s.trimEnd()//remove space from end
135+
// console.log(str);
136+
// console.log(str1);
137+
// console.log(str2);
138+
139+
140+
// padStart() -- padEnd() //
141+
142+
// SYNTAXES
143+
144+
// string.padStart(targetlength) ----- string.padEnd(targetlength) ///
145+
// string.padStart(targetlength,padstring) ---- string.padEnd(targetlength,padstring) ///
146+
147+
// const s = 'abc';
148+
// const m = s.padStart(10)// _ _ _ _ _ _ _ abc <---result will appear
149+
// console.log(s.padStart(10,'tim'))// "timtimtabc" <-- it returns like this
150+
// console.log(s.padStart(10,'123456789'))// "1234567abc"-- it returns like this
151+
// console.log(s.padEnd(10));//"abc_ _ _ _ _ _ _" it returns with 7 space
152+
// console.log(s.padEnd(10,'foo'));// "abcfoofoof" <-- it returns
153+
// console.log(s.padEnd(10,'123456789'));// "abc1234567" <-- it returns

‎String methods/tempCodeRunnerFile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const string = 'The morning is upon us';

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /