for in en 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]}`);
}
// expected output:
// "a: 1"
// "b: 2"
// "c: 3"
Example 2: for javascript
var texts = [
'a1',
'a2',
'a3',
];
for (var i = 0; i < texts.length; i++) {
console.log(texts[i]);
}
/* Result
a1
a2
a3
*/
Example 3: for in javascript
var colors=["red","blue","green"];
for (let i = 0; i < colors.length; i++) {
console.log(colors[i]);
}