-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
94 lines (62 loc) · 1.92 KB
/
app.js
File metadata and controls
94 lines (62 loc) · 1.92 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
var name1 = "Maaz";
var name2 = "Ahmed";
var name3 = "Hasan";
//What is Array ? Array store multiple data in it
var names = ["Maaz","Hasan","Ahmed","Sheikh","Shams"];
console.log(names);
// Length of Array :
var Length = names.length
console.log(length);
//Getting Value From Array Index :
var index = names[2]
console.log("Index 2 : " + length);
//Last Index of array
console.log("Last Index : " + names[names.length - 1]);
//First Index of array
console.log("First Index : " + names[0]);
//Second Last Index of array
console.log("Second Last Index : " + names[names.length - 2]);
//Update Value In Array
names[3] = "Sheikh3";
console.log(names);
//Add Value In Array
names[names.length] = "Added";
console.log(names);
var country = ["Pakistan","India","Bangladesh"];
console.log(country);
//Methods Of Array :
// 1.Push
// 2.Pop
// 3.Shift
// 4.Unshift
// 5.Splice
// 6.Slice
// Push == To Add Element in the end of an array
country.push("China","Afghanistan");
console.log("After Push : " , country);
// Pop == To Remove last element from array
country.pop();
console.log("After Pop : " , country);
// UnShift == To Add value in the start of array
country.unshift("Sri Lanka");
console.log("After Unshift : " , country);
// Shift == To remove first element from array
country.shift();
console.log("After Shift : " , country);
// Splice == To add or remove from particular index of array
var fruits = ["Apple","Mango","Banana","PineApple","Strawberry","Guava"];
// To add at particular index
fruits.splice(1,0,"Peach","Leeche");
console.log(fruits);
// To remove from particular index
var deleted = fruits.splice(2,1);
console.log("Deleted Value : " , deleted);
console.log(fruits);
// To add or remove both
var updated = fruits.splice(4,1,"Kiwi");
console.log("Updated Value : " , updated);
console.log(fruits);
//Slice == Use to copy element
var copy3 = fruits.slice(1,4);
console.log("Copied : " , copy3);
console.log(fruits);