1+ /*
2+ * JavaScript Higher Order Array Loop
3+ */
4+
5+ // ['', '', '', 1, true][({}, {}, {})];
6+
7+ const fruits = [ 'Mango' , 'Banana' , 'Orange' , 'Graps' ] ;
8+
9+ for ( let fruit = 0 ; fruit < fruits . length ; fruit ++ ) {
10+ // console.log(fruits[fruit]);
11+ }
12+
13+ for ( const fruit of fruits ) {
14+ // console.log(fruit);
15+ }
16+
17+ const myName = 'Ali Hossain' ;
18+ for ( const name of myName ) {
19+ // console.log(`Each char is ${name}`);
20+ }
21+
22+ const country = new Map ( [
23+ [ 'Bn' , 'Bangladesh' ] ,
24+ [ 'In' , 'India' ] ,
25+ [ 'Pk' , 'Pakistan' ] ,
26+ [ 'Np' , 'Nepal' ] ,
27+ ] ) ;
28+
29+ country . set ( 'Vu' , 'Vutan' ) ;
30+
31+ // country.set('Bn', 'Bangladesh');
32+
33+ // for (const key of country) {
34+ // console.log(key);
35+ // }
36+
37+ for ( const [ key , value ] of country ) {
38+ // console.log(key, ':', value);
39+ }
40+
41+ const myCountry = {
42+ Bn : 'Bangladesh' ,
43+ In : 'India' ,
44+ Pk : 'Pakistan' ,
45+ Np : 'Nepal' ,
46+ } ;
47+ // for (const key of myCountry) {
48+ // console.log(key);
49+ // }
50+
51+ // for (const key in myCountry) {
52+ // console.log(key, ':', myCountry[key]);
53+ // }
54+
55+ for ( const key of Object . keys ( myCountry ) ) {
56+ // console.log(key);
57+ }
58+
59+ for ( const key in fruits ) {
60+ // console.log(fruits[key]);
61+ }
62+
63+ // fruits.forEach(function (fruit) {
64+ // console.log(fruit);
65+ // });
66+
67+ // fruits.forEach(fruit => {
68+ // console.log(fruit);
69+ // });
70+
71+ // function myFruit(fruit) {
72+ // console.log(fruit);
73+ // }
74+ // fruits.forEach(myFruit);
75+
76+ fruits . forEach ( ( fruit , index , arr ) => {
77+ // console.log(fruit, index, arr);
78+ } ) ;
79+
80+ const stack = [
81+ {
82+ name : 'MERN Stack' ,
83+ property : 'Mongo, Express, React, Node' ,
84+ } ,
85+ {
86+ name : 'Laravel' ,
87+ property : 'JavaScript, Vue, PHP, Laravel, MySQL' ,
88+ } ,
89+ {
90+ name : 'WordPress' ,
91+ property : 'JavaScript, PHP, WordPress, MySQL' ,
92+ } ,
93+ ] ;
94+ stack . forEach ( info => {
95+ console . log ( `Want to learn ${ info . name } ? Learn this ${ info . property } ` ) ;
96+ } ) ;
0 commit comments