0

How can I get the value "success" if the value that stands in place "Everlasting hair" is changing?

{ 
'Everlasting hair' :
   { succes : true,
     volume:'12'
   }
}
zip_file
  • 11
  • 2

1 Answers1

1

You can discover the property names in the object via for-in or Object.keys. Object.keys, for instance, will give you an array of the object's own, enumerable properties. If you know for sure there will only be one, then:

var success = yourObject[Object.keys(yourObject)[0]].succes;
// Another s here? It's missing in the question -----------^

On cutting-edge JavaScript engines with Object.values (new in ES2017, but polyfillable), as Keith points out if you don't need the name you can use Object.values instead:

var success = Object.values(yourObject)[0].succes;
// Another s here? It's missing in the question -^
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875