javascript for object.keys 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 object keys

var myObj = {no:'u',my:'sql'}
var keys = Object.keys(myObj);//returnes the array ['no','my'];