javascript for in loops code example
Example 1: javascript for loop
var i;
for (i = 0; i < 10 ; i++) {
}
Example 2: for in javascript
const object = {a: 1, b: 2, c: 3};
for (const property in object) {
console.log(`${property}: ${object[property]}`);
}
Example 3: for in loop javascript
var person = {"name":"taylor","age":31};
for (property in person) {
console.log(property,person[property]);
}
Example 4: javascript for loop
var colors=["red","blue","green"];
for (let i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
Example 5: for in loop javascript
function diagonalDifference(arr) {
let n = arr.length;
let pri,sec = 0;
pri = sec = 0;
for (let i= 0; i < n; i++) {
pri += arr[i][i];
sec += arr[i][n - i - 1];
}
if(pri==sec){
return (0);
}else {
if (pri>sec){
return (pri-sec);
}else{
return (sec-pri);
}
}
}