Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to access immediate unknown key in object

Tags:

javascript

how to access immediate unknown key in object. in pic "367:sl" is dynamic key and i want to access cptyName value which is in "367:sl". Thanks in advance

pic

like image 304
Amit Avatar asked Jun 19 '14 08:06

Amit


People also ask

How do you find the value of an object without a key?

How to get all property values of a JavaScript Object (without knowing the keys) ? Method 1: Using Object. values() Method: The Object. values() method is used to return an array of the object's own enumerable property values.


1 Answers

If your dynamic key is the only key in quotes object, you can get the first key and then access value with:

var firstKey = Object.keys(quotes)[0];
var cptyName = quotes[firstKey].cptyName;

http://jsfiddle.net/mGZpa/

like image 102
Michael Radionov Avatar answered Oct 16 '22 17:10

Michael Radionov