0

I am passed an object lets say called myobj.

Key: last, Value: "Yellow"

To get the key it is

Object.keys(myobj) // = ["last"]

To get the value it is

myobj.last // = "Yellow"

But I want to handle any key. So in pseudo code I want to combine these.

myobj.Object.keys(myobj)  // to return "Yellow" or whatever the incoming key of the object is.
Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188
JohnnyBizzle
  • 971
  • 3
  • 17
  • 31

1 Answers1

2

You can use square bracket notation to access object property

var myobj = {
  last: "yellow"
};

var res = myobj[Object.keys(myobj)[0]];

document.write(res);
Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188