[英]JSON / JavaScript get object keys
I'm extracting data from as follows - 我从以下提取数据-
The above function returns data in the below format - 上面的函数以以下格式返回数据-
[Object { date=Date, value=112, volume=1469}, Object { date=Date, value=124, volume=539}, Object { date=Date, value=114, volume=859}, Object { date=Date, value=123, volume=1284}, Object { date=Date, value=113, volume=1382}, Object { date=Date, value=129, volume=1353}]
I would like to obtain the list of keys only as a simple array.(Parsing the first object in the array is enough to get this as all other objects have the same keys) In case of the above output, I would like the simple array to look as ["date","value","volume"]
我只想以简单数组的形式获取键的列表。(解析数组中的第一个对象就足以获取此键,因为所有其他对象都具有相同的键)在上述输出的情况下,我想要简单数组看起来像
["date","value","volume"]
I tried JSON.stringify
& then parse but it still doesn't work. 我尝试了
JSON.stringify
并进行了解析,但仍然无法正常工作。
Also, how could I convert the whole array obtained from the chart into a simple array please? 另外,如何将从图表中获得的整个数组转换为简单数组?
I'm visualizing an output of the below type - 我正在可视化以下类型的输出-
[{'date':'whatever', 'value':126, 'volume':911},
{'date':'whatever', 'value':136, 'volume':1005},
{'date':'whatever', 'value':125, 'volume':720}]
If the question doesn't make sense, please let me know. 如果这个问题没有道理,请告诉我。 I'll see how best I could re-word.
我将看看如何才能最好地重述。
Use Object.keys()
function. 使用
Object.keys()
函数。 Here in the response from function you get an array. 在函数的响应中,您得到一个数组。 Use that to get the list of keys.
使用它来获取键列表。
var data = getChartData('param')
Object.keys(data[0]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.