Skip to content

Commit ba6334c

Browse files
committed
update new array _string
1 parent 01c2af0 commit ba6334c

File tree

2 files changed

+194
-0
lines changed

2 files changed

+194
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
8+
<script>
9+
10+
11+
data = ['nishant', 'jain', 24, 'javascript']
12+
13+
console.log(data[3])
14+
15+
// push()
16+
17+
data.push('python')
18+
console.log(data)
19+
20+
// pop()
21+
data.pop()
22+
console.log(data)
23+
24+
// unshift()
25+
data.unshift('hello')
26+
console.log(data)
27+
28+
// shift()
29+
data.shift()
30+
console.log(data)
31+
32+
// length
33+
console.log(data.length)
34+
35+
// indexOf()
36+
console.log(data.indexOf(24))
37+
38+
// includes()
39+
console.log(data.includes('javascript'))
40+
41+
// concat() -> add two arrays
42+
data2 = ['html', 'css']
43+
new_data = data.concat(data2)
44+
console.log(new_data)
45+
46+
// slice() -> extract a portion of an array
47+
console.log(new_data.slice(0, 4))
48+
49+
// splice() -> add 0
50+
new_data.splice(2,0,'python')
51+
console.log(new_data)
52+
// splice() -> remove 1 element
53+
new_data.splice(2,1)
54+
console.log(new_data)
55+
56+
// reverse()
57+
data = [1, 2, 3, 4, 5]
58+
console.log(data.reverse())
59+
60+
// join -> convert array to string
61+
data = ['nishant', 'jain', 24, 'javascript']
62+
console.log(data.join(" "))
63+
64+
// sort()
65+
data = [5, 2, 8, 1, 4]
66+
console.log(data.sort())
67+
68+
// using loop to iterate over array
69+
70+
data = ['nishant', 'jain', 24, 'javascript']
71+
72+
for(i = 0;i<data.length;i++){
73+
console.log(data[i])
74+
}
75+
76+
// map()
77+
78+
data = [1, 2, 3, 4, 5]
79+
new_data = data.map(function(value){
80+
return value * 2
81+
})
82+
console.log(new_data)
83+
84+
// filter()
85+
data = [1, 2, 3, 4, 5]
86+
87+
new_data = data.filter(function(value){
88+
return value % 2 === 0
89+
})
90+
console.log(new_data)
91+
92+
// reduce()
93+
data = [1, 2, 3, 4, 5]
94+
sum = data.reduce(function(a, b){
95+
return a + b
96+
}, 0)
97+
console.log(sum)
98+
99+
// find()
100+
data = [1, 2, 3, 4, 5]
101+
new_data = data.find(function(value){
102+
return value > 3
103+
})
104+
console.log(new_data)
105+
106+
107+
108+
109+
110+
</script>
111+
112+
</head>
113+
<body>
114+
115+
</body>
116+
</html>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
8+
<script>
9+
10+
//data = "codeswithpankaj"
11+
12+
first_name = "Nishant"
13+
last_name = "jain"
14+
15+
// concatenation
16+
17+
full_name = first_name + " " + last_name
18+
console.log(full_name)
19+
20+
// use strin methods concat()
21+
22+
full_name = first_name.concat(" ", last_name)
23+
console.log(full_name)
24+
25+
// length of string
26+
console.log(full_name.length)
27+
28+
data = "codeswithpankaj"
29+
30+
// substring
31+
console.log(data.substring(0, 5))
32+
33+
// replace
34+
console.log(data.replace("pankaj", "nishant"))
35+
36+
// toUpperCase
37+
console.log(data.toUpperCase())
38+
39+
// toLowerCase
40+
console.log(data.toLowerCase())
41+
42+
// slice
43+
console.log(data.slice(0, 5))
44+
45+
// split
46+
data = "apple,banana,grapes"
47+
console.log(data.split(","))
48+
49+
// trim
50+
data = " hello world "
51+
console.log(data)
52+
console.log(data.trim())
53+
54+
// charAt
55+
data = "codeswithpankaj"
56+
console.log(data.charAt(0))
57+
58+
console.log(data[0])
59+
60+
// indexOf
61+
console.log(data.indexOf("a"))
62+
63+
// lastIndexOf
64+
console.log(data.lastIndexOf("a"))
65+
66+
// includes
67+
console.log(data.includes("python"))
68+
69+
70+
71+
</script>
72+
73+
74+
</head>
75+
<body>
76+
77+
</body>
78+
</html>

0 commit comments

Comments
 (0)