javascript get key value from object code example

Example 1: javascript iterate object key values

Object.entries(obj).forEach(([key, value]) => {
	console.log(key, value);
});

Example 2: javascript object get value by key

const person = {
  name: 'Bob',
  age: 47
}

Object.keys(person).forEach((key) => {
  console.log(person[key]); // 'Bob', 47
});

Example 3: object keys javascript

const object1 = {
  a: 'somestring',
  b: 42,
  c: false
};

console.log(Object.keys(object1));
// expected output: Array ["a", "b", "c"]

Example 4: object.keys javascript

const object1 = {
  a: 'somestring',
  b: 42,
  c: false
};

console.log(Object.keys(object1));

Example 5: javascript object get value by key

var obj = {
   a: "A",
   b: "B",
   c: "C"
}

console.log(obj.a);  // return string : A

var name = "a";
console.log(obj[name]);