javascript for in loop
let str = "";
for (let i = 0; i < 9; i++) {
str = str + i;
}
console.log(str);
// expected output: "012345678"
const object = {a: 1, b: 2, c: 3};
for (const property in object) {
console.log(`${property}: ${object[property]}`);
}var p = {
"p1": "value1",
"p2": "value2",
"p3": "value3"
};
for (var key in p) {
if (p.hasOwnProperty(key)) {
console.log(key + " -> " + p[key]);
}
}for (var property in object) {
if (object.hasOwnProperty(property)) {
// Do things here
}
}Example:
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"
Syntax:
for (variable in object)
statementconst p = {
"p1": "value1",
"p2": "value2",
"p3": "value3"
};
for (let [key, value] of Object.entries(p)) {
console.log(`${key}: ${value}`);
}
Also in JavaScript:
- check if 2 arrays are equal javascript
- javascript array split chunk
- javascript map array
- javascript document.createElement add function
- node js TypeError [ERR_INVALID_ARG_TYPE]: The argument must be of type string. Received undefined
- puppeteer stealth popup
- javascript ajax show result type min 3 characters
- string interpolation in javascript
- javascript findindex
- count duplicates array js
- get children length jquery
- in javascript check is is an array or not
- js convert nodelist to array
- javascript find element in array and remove
- javascript path folder above
- javascript get array min and max
- sum all elements in array javascript
- ejs-multiselect
- angular ng-click toggle class
- react js material ui
- change url without reloading
- reactive localstorage in react
- change class javascript
- javascript create array of objects with key