-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathscript.js
38 lines (29 loc) · 1.02 KB
/
script.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
// ARRAY METHOD
const friends = ["Michael", "Steven", "Peter"];
console.log(friends);
// [Length] Sets or returns the number of elements in an array
console.log(friends.length);
// [Push] - Add elements to the end of an array
friends.push("Jay");
console.log(friends);
// [Unshift] - Add elements to the beginning of an array
friends.unshift("John");
console.log(friends);
// [Pop] - Removes last element of the array
friends.pop();
const popped = friends.pop();
console.log(popped);
// [Shift] - Removes first element of the array
friends.shift();
console.log(friends);
// [IndexOf] - Tells us the position of an element in the array.
console.log(friends.indexOf("Michael"));
// Returns -1 if we check an element that is not in the array.
console.log(friends.indexOf("Bob"));
// Includes() - Check if an array contains the specified element using strict equality.
friends.push(23);
console.log(friends.includes("23"));
// Conditionals with includes()
if (friends.includes("Steven")) {
console.log("You have a friend called Steven");
}