find key value pair in object javascript code example

Example 1: for key value in object javascript

for (const [key, value] of Object.entries(object1)) {
  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: 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]);