for in and for of difference code example
Example 1: for in and for of in js
Object.prototype.objCustom = function () {};
Array.prototype.arrCustom = function () {};
let iterable = [3, 5, 7];
iterable.foo = "hello";
for (let i in iterable) {
console.log(i);
}
for (let i of iterable) {
console.log(i);
}
Example 2: for in and for of in js
let iterable = new Map([["a", 1], ["b", 2], ["c", 3]]);
for (let entry of iterable) {
console.log(entry);
}
for (let [key, value] of iterable) {
console.log(value);
}