for key value of object javascript code example
Example 1: javascript for key in object
// iterates over all enumerable properties of an object that are
// keyed by strings (ignoring ones keyed by Symbols),
// including inherited enumerable properties.
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: js variable for key obj
{
[yourKeyVariable]: someValueArray,
}