forin in javascript code example
Example 1: for in javascript
const object = {a: 1, b: 2, c: 3};
for (const property in object) {
console.log(`${property}: ${object[property]}`);
}
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 of and for in javascript
let arr = ['el1', 'el2', 'el3'];
arr.addedProp = 'arrProp';
for (let elKey in arr) {
console.log(elKey);
}
for (let elValue of arr) {
console.log(elValue)
}
Example 4: for in javascript
var colors=["red","blue","green"];
for (let i = 0; i < colors.length; i++) {
console.log(colors[i]);
}