object - Javascript - Get the associative array key value -


i have object 1 key value given below -

var = {}; a.x = "randomvalue"; 

my requirement access value "randomvalue", catch dont know property name "x".

simplest way value??

try:

var v, i; var = {}; a.x = "randomvalue"; (x in a) {   if a[x] === "randomvalue" {     v = x;     = "randomvalue";   } } 

then v contains object key , i contains object value (although don't need it).

or, if know value index:

var obj = { first: 'someval' }; obj[object.keys(obj)[0]]; //returns 'someval' 

Comments