1var colors=["red","blue","green"];
2for (let i = 0; i < colors.length; i++) {
3 console.log(colors[i]);
4}
1var person = {"name":"taylor","age":31};
2for (property in person) {
3 console.log(property,person[property]);
4}
5//name taylor
6//age 31
1var subjects = {
2 'math': 85,
3 'physics': 75,
4}
5
6for (var i in subjects) {
7 console.log(i + ' : ' + subjects[i]);
8}
9
10// math : 85
11// physics : 75
1let array = [1,2,3,4,5,6,7,8,9,10];
2// our array that we will use the for loop on
3for (let i = 0; i < array.length; i++) {
4 // this loop will console log the element at array[i] starting at 0
5 // and will continue looping for i < array.length
6 console.log(array[i]);
7 // after each loop i will increase by 1
8}
9
10// this will console log
11// 1
12// 2
13// 3
14// 4
15// 5
16// 6
17// 7
18// 8
19// 9
20// 10
21
1
2let arry = {
3 name: "Rakibul Islam",
4 class: "Tane",
5 grup: "A",
6 roll: 10,
7 sub: "Arse"
8}
9//for in loop used to object
10for(let i in arry){
11 console.log(i,arry[i]);
12}
1function diagonalDifference(arr) {
2 // Write your code here
3 // return (arr); 11,2,4,4,5,6,10,8,-12
4 let n = arr.length;
5 let pri,sec = 0;
6
7 pri = sec = 0; //initialize both diagonal sum to 0
8 for (let i= 0; i < n; i++) {
9 //console.log( "PRI(arr)= ", i,i);
10 //console.log( arr[i][i]);
11 //console.log( "SEC(arr)= ", i,n-i-1);
12 //console.log( arr[i][n-i-1]);
13 pri += arr[i][i];
14 sec += arr[i][n - i - 1];
15 }
16
17 // return |x| is the absolute value of x
18 if(pri==sec){
19 return (0);
20 }else {
21 if (pri>sec){
22 return (pri-sec);
23 }else{
24 return (sec-pri);
25 }
26 }
27}