-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy patharray-object.js
More file actions
65 lines (53 loc) · 1.3 KB
/
Copy patharray-object.js
File metadata and controls
65 lines (53 loc) · 1.3 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
// let arr = new Array("Apple", "Banana", "Mango");
let arr = ["Apple", "Banana", "Mango"];
arr.push("Orange"); // adds at the end
arr.pop(); // removes from the end
arr.shift(); // removes from the beginning
arr.unshift("Caramel"); // adds at the beginning
// arr[3] = "Watermelon";
// console.log("Initial array:", arr);
let arr1 = ["I", "study", "JavaScript", "right", "now"];
let numArr = [2, 4, 6, 8, 10];
// for (let i = 0; i < numArr.length; i++) {
// console.log(numArr[i] * 2);
// }
// numArr.forEach((i) => {
// console.log(i * 2);
// });
// for (let value of numArr) {
// console.log(value * 3);
// }
// for (let index in numArr) {
// console.log(numArr[index] * 4);
// }
// remove 3 first elements and replace them with another
// arr1.splice(2, 1, "Rust");
// let arrSlice = arr1.slice(-4);
// console.log("Modified array:", numArr);
let arrOfObj = [
{
name: "John",
age: 30,
isAdmin: true,
courses: ["html", "css", "js"],
wife: null,
},
{
name: "kelechi",
age: 25,
isAdmin: false,
courses: ["python", "django"],
wife: null,
},
{
name: "Goodluck",
age: 28,
isAdmin: false,
courses: ["java", "spring"],
wife: null,
},
];
arrOfObj.map((user) => {
console.log("User:", user.age + 3);
});
// console.log("Object:", arrOfObj);