-
Notifications
You must be signed in to change notification settings - Fork 0
/
array.js
74 lines (52 loc) · 1.4 KB
/
array.js
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
let marks = [1, 2, 3, 4, 6, 5];
console.log(typeof marks)
let yourName = ["anuj", "ram", "shyam", "hari", "steve"];
let mixed = ["str", 12, true, [9, 8, 7]];
console.log("marks: ", marks, "yourName: ", yourName, "mixed: ", mixed);
let array = new Array("copy", "cut", "paste", "undo", "redo");
console.log(array);
console.log(array[1]);
array[0] = "new";
console.log(array.length);
console.log(Array.isArray(array));
console.log(array.indexOf("cut"));
// Mutating or Modifing
let marks2 = [100, 101, 102, 103, 104];
console.log(marks);
marks.unshift(0);
console.log(marks);
console.log(marks.push(7));
console.log(marks);
marks.shift();
console.log(marks);
marks.pop();
console.log(marks);
marks.sort();
console.log(marks);
marks.reverse();
console.log(marks);
marks = marks.concat(marks2);
console.log(marks);
marks = marks.join(" and ");
console.log(marks);
marks = marks.slice(1,3);
console.log(marks);
const arr = ['Hello'];
arr.splice(1, 0, 'World');
console.log(arr)
// marks.splice(2, 3, 001, 002, 003, 004); //not valid because highly manipulated.
console.log(marks);
delete marks2[2];
console.log(marks2)
// console.log(typeof marks);
marks.toString();
console.log(typeof marks);
//Object
// let myobject = {
// yourName: "Anuj",
// class: 12,
// student: true,
// subjects: [101, 102, 103, 104, 105, 107],
// };
// console.log(myobject.yourName);
// console.log(myobject["yourName"]);