js for in index code example
Example 1: javascript enumerate with index
const iterable = [...];
for (const [index, elem] in iterable.entries()) {
f(index, elem);
}
iterable.forEach((elem, index) => {
f(index, elem);
});
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 of index
let array = ["foo", "bar"]
let low = 0;
let high = array.length;
for(let i = low; i < high; i++) {
console.log(i);
console.log(array[i]);
}
Example 5: function for searching in map in c++
unordered_map<int,int> m1;
m1.find(value of element you want to find);