-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path07b-array-loop.js
More file actions
53 lines (42 loc) · 1.15 KB
/
07b-array-loop.js
File metadata and controls
53 lines (42 loc) · 1.15 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
// Iteration on Arrays
// Always have 2 types of loops on Arrays
// For Each and Map
// some of the loops on array are being directly added into the properties
// in prototypes parameter of Loops such as "for each and map" is being injected in by deault
const coding = ["js", "ts", "ruby"]
coding.forEach((items) => {
console.log(items);
})
// passing a function with a function as a Parameter
function printMe (item){
console.log(item);
}
coding.forEach(printMe); // only passed refernce of function not () otherwise execute directly there
coding.forEach( (item, index, arr) => {
console.log(item, index, arr);
})
// [ {} , {}, {}]
// we have to learn iteration on Array of Objects
// coz from DB data comes in the form of array from and each value is an Object
// Doing that using For Each Loop
let myCoding = [
{
languagename: "javaScript",
lagFile: "js"
},
{
languagename: "java",
lagFile: "java"
},
{
languagename: "pyhon",
lagFile: "py"
},
{
languagename: "Typescript",
lagFile: "TS"
},
]
myCoding.forEach( (item) => {
item.languagename
})