how to convert JSON array into JavaScript 2D array -


this question has answer here:

i want convert following json js 2d array, not sure how in html.

[{"fields": {"diameter": 23.0, "neighbourhood": "west end"}, "model": "hug.tree", "pk": 345},   {"fields": {"diameter": 14.0, "neighbourhood": "mount pleasant"}, "model": "hug.tree", "pk": 484}] 

the result should like:

[[23.0, 'west end'], [14.0, 'mount pleasant']] 

thank much!

this work fields of "fields", not diameter or neighborhood.

demo:

var items = [{"fields": {"diameter": 23.0, "neighbourhood": "west end"}, "model": "hug.tree", "pk": 345}, {"fields": {"diameter": 14.0, "neighbourhood": "mount pleasant"}, "model": "hug.tree", "pk": 484}];    var = 0, result = [];    while(i < items.length){      result.push([])      for(var key in items[i].fields){          result[result.length-1].push(items[i].fields[key])	      }      i++  }    document.write(json.stringify(result, null, 4));


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -