-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08-array-methods.js
More file actions
58 lines (50 loc) · 1.41 KB
/
Copy path08-array-methods.js
File metadata and controls
58 lines (50 loc) · 1.41 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
const items = [
{ name: "Bike", price: 100 },
{ name: "key", price: 30 },
{ name: "Lite", price: 450 },
{ name: "Phone", price: 100 },
{ name: "Computer", price: 850 },
{ name: "Book", price: 200 }
];
// Filter method
const filteredItems = items.filter((item) => {
return item.price <= 100;
});
// console.log(filteredItems)
// Map method
const itemNames = items.map((item) => {
// return item.name;
return item.price;
});
// console.log(itemNames);
// Find method
const foundItem = items.map((item) => {
return item.name === "Book";
});
// console.log(foundItem);
// forEach
items.forEach((item) => {
console.table(item.name);
});
// Some method
// Some check 1st one item if it gets 1st conditioning the requirements it will return true or if it did not find anything in the array according to the condition it will return false
const hasInexpensiveItems = items.some((item) => {
return item.price <= 100;
});
// console.log(hasInexpensiveItems);
// Every method
// Every check every item in the array and then return True or Flase.
const checkEveryItem = items.every((item) => {
return item.price <= 100;
});
// console.log(checkEveryItem);
// Reduce method
//
const total = items.reduce((currentTotal, item) => {
return item.price + currentTotal;
}, 0);
// console.log(total);
const numItems = [1, 2, 3, 4, 5, 6];
// includes method
const includesTwo = numItems.includes(2);
// console.log(includesTwo);