Skip to content

Commit b66f441

Browse files
author
codewithghan
committed
array map, filter, find, reduce, with for, for-of, forEach loop
1 parent c51f67d commit b66f441

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

array_phase2.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
3+
// for-loop
4+
// for(let i=0; i<=numberArray.length; i++ ){
5+
// console.log(i, numberArray[i]);
6+
// }
7+
8+
// for-of
9+
// for(elem of numberArray) {
10+
// console.log(elem);
11+
// }
12+
13+
// forEach loop
14+
// numberArray.forEach(ele => {
15+
// console.log(ele, "foreach");
16+
// });
17+
18+
// map
19+
const numberArray = [10,20,30,40];
20+
const newArr = numberArray.map((ele)=> {
21+
return ele*2;
22+
});
23+
// console.log(numberArray);
24+
// console.log(newArr);
25+
26+
// filter array
27+
const numberArrayfilter = [10,20,30,40];
28+
const newArrfil = numberArrayfilter.filter((ele)=> {
29+
return ele > 20;
30+
});
31+
// console.log(numberArrayfilter);
32+
// console.log(newArrfil);
33+
34+
const numberArrayfind = [10,20,30,40];
35+
const newArrfind = numberArrayfind.find((ele)=> {
36+
return ele > 20;
37+
});
38+
// console.log(numberArrayfilter);
39+
// console.log(newArrfind);
40+
41+
42+
43+
const myArr = [1,2,3,4];
44+
// let sum = 0;
45+
// myArr.forEach((res)=>{
46+
// sum = sum + res;
47+
// });
48+
// Reduce Method
49+
const reduceArray = myArr.reduce((sum, res) => {
50+
return sum + res;
51+
},0);
52+
53+
// console.log(reduceArray);

0 commit comments

Comments
 (0)