forked from Assassin1771/HACKTOBERFEST-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray methods.js
75 lines (44 loc) · 1.65 KB
/
array methods.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
75
// array methods
//map
// filter
// reduce
//=> arrow function
//map it maps the elemets and change evary elament or iterate every element
// const ourarray = [1,2,3,4,5];
// const neyarray = ourarray.map((data)=>{
// return data +10;
// });
// console.log(neyarray)
//filter
// it is used to filter the elements like we did hear using < operator
// const ourarray = [1,2,3,4,5];
// const neyarray = ourarray.filter((data)=>{
// return data <3 ;
// });
// console.log(neyarray)
// reduce
// it only return 1 value either one value , or might be a string etc
// it is like a loop and it iterates till we add all elments acummulator stores the nect value and current value stores the current value after the addition
// these name are choise we can use any of our wish but is is recomended to use those names
// const ourarray = [1,2,3,4,5];
// const newarray = ourarray.reduce((accumulator,currentval)=>{
// return accumulator + currentval;
// },0);
// console.log(newarray);
// console.log(ourarray);
// promises
// it either rejects or resolves th promises but after some time
let concert = true;
let attendConcert = new Promise((resolve , reject)=>{
setTimeout(()=>
{
if (concert) resolve ("we did attend the cencert");
else reject("we failed to attend");
},2000);
});
// then and catch to make the output
// then to make the out put come if there is any output
attendConcert.then((sujay)=> console.log(sujay));
// it catches the error itf there is any
attendConcert.catch((Error)=> console.log(Error));
// async and await are promises