javascript object get value by key code example

Example 1: get keys of dictionary js

// Get keys of a dictionary
let dict = { a:1 , b:2 , c:3 }

console.log( Object.keys(dict) ) // expected output : ['a', 'b', 'c']

Example 2: object to array javascript

Object.values(obj)

Example 3: javascript object get value by key

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

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

Example 4: js find key by value in object

Object.keys(object).find(key => object[key] === value)

Example 5: js object keys

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

Example 6: 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]);