简体   繁体   中英

jquery how to get the value of the array of array from json

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.

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];
    }
}
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])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM