Answers for "for key value in js object"

4

iterate key value object javascript

'use strict';
// ECMAScript 2017
const object = {'a': 1, 'b': 2, 'c' : 3};
for (const [key, value] of Object.entries(object)) {
  console.log(key, value);
}
Posted by: Guest on September-02-2020
2

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"
Posted by: Guest on February-25-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language