Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

get the key of largest json array value

var jsonText = '{"data":{"one":21,"two":35,"three":24,"four":2,"five":18},"meta":{"title":"Happy with the service"}}'
var data = JSON.parse(jsonText).data
var maxProp = null
var maxValue = -1
for (var prop in data) {
  if (data.hasOwnProperty(prop)) {
    var value = data[prop]
    if (value > maxValue) {
      maxProp = prop
      maxValue = value
    }
  }
}
Source by web.archive.org #
 
PREVIOUS NEXT
Tagged: #key #largest #json #array
ADD COMMENT
Topic
Name
4+8 =