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
  • 110,383
  • 23
  • 155
  • 178
JohnnyBizzle
  • 963
  • 1
  • 16
  • 30

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
  • 110,383
  • 23
  • 155
  • 178