-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray.html
More file actions
70 lines (56 loc) · 2.33 KB
/
Array.html
File metadata and controls
70 lines (56 loc) · 2.33 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
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h3> Javascript array </h3>
<script>
let name = [];
console.log(name);//[]
let course = ["CSS" ,"HTML","Javascript" , "PHP" , "Vuejs"];
console.log(course);
// creating array consturtor
let subject = new Array();
//add element in the array
subject.push("Maths");//1
subject.push("Science");//2
subject.unshift("Social Science ");// index 0
console.log(subject);
let sub_name = new Array("Java", "advance java" , "spring boot");
console.log(sub_name) ;
// initializing Array while declaring
let arr = new Array(3);
arr[0] = 100;
arr[1] = 200;
arr[2] = 300;
console.log(arr);console.log(arr[1]);
// replacing exsisting value
arr[0] = "bootstrap";
console.log(arr);
//remove elements from an array using pop() and shift() methods
let courses = ["HTML", "CSS", "Javascript", "React", "Node.js"];
console.log("oriignal array : "+courses);
let lastelement = courses.pop();
console.log("lastelement : "+lastelement);
let firstele = courses.shift();
console.log("First element removed : "+firstele);
courses.splice(1 , 2);//removing two element starting from second position
console.log("After removing 2 elements starting from index 1 :"+courses)
// increse or decrease array size
let users = ["A" ,"b","c","x","Z","y"];// length is 6
console.log(users.length);
users.length = 10;//increase the array size by setting the
console.log("after increasing the length of the array "+users);
users.length = 2;//decreasing the array size by setting the length property
console.log("after decreasing the length of the array "+users);
//join method - helps to join two arrays as a string
console.log("join method")
var fruits=["apple","banana","cherry"];
console.log(" after join : "+fruits.join('|'));
var colors=['red','blue','green'];
//concate method
let newArr = fruits.concat(colors);
console.log(newArr);
</script>
</body>
</html>