0

I have this 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
    ]
  ]
}

I need to get the value of the of the first array of the last element in that json

in my example I need to get the 1332838400000

I couldn't do that myself. sorry.

user2208349
  • 7,429
  • 5
  • 26
  • 35

2 Answers2

1

To get the highest of the first elements of each of the elements:

var max = -Infinity;
for (var key in json) {
    var arr = json[key];
    if (arr[0][0] > max) {
        max = arr[0][0];
    }
}
Barmar
  • 741,623
  • 53
  • 500
  • 612
-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])
user3141004
  • 115
  • 4