我有这个json
{
"default": [
[
1325876000000,
0
],
[
1325876000000,
0
],
[
1325876000000,
0
],
[
1325876000000,
0
]
],
"direct": [
[
1328196800000,
0
],
[
1328196800000,
100
],
[
1328196800000,
0
],
[
1328196800000,
0
]
],
"Sales": [
[
1330517600000,
0
],
[
1330517600000,
0
],
[
1330517600000,
90
],
[
1330517600000,
0
]
],
"Support": [
[
1332838400000,
0
],
[
1332838400000,
0
],
[
1332838400000,
0
],
[
1332838400000,
0
]
]
}
我需要获取该json
中最后一个元素的第一个数组的值在我的示例中,我需要获取1332838400000
我自己也做不到。遗憾。
答案 0 :(得分:1)
获取每个元素的第一个元素中的最高元素:
var max = -Infinity;
for (var key in json) {
var arr = json[key];
if (arr[0][0] > max) {
max = arr[0][0];
}
}
答案 1 :(得分:-1)
var json = '{"default":[[1325876000000,0],[1325876000000,0],[1325876000000,0],[1325876000000,0]],"direct":[[1328196800000,0],[1328196800000,100],[1328196800000,0],[1328196800000,0]],"Sales":[[1330517600000,0],[1330517600000,0],[1330517600000,90],[1330517600000,0]],"Support":[[1332838400000,0],[1332838400000,0],[1332838400000,0],[1332838400000,0]]}';
var parser = $.parseJSON(json)
var key = keys(parser)
var len = key.length
var last = key[(len-1)]
alert(parser[last][0][0])