convert json object to javascript array -
after mysql query, used json_encode convert result of query , i'm getting following:
[ {"id":"1","map_id":"1","description":"this athens","lat":"37.77994127700315","lng":"23.665237426757812","title":"athens"}, {"id":"2","map_id":"1","description":"this rome","lat":"41.9100711","lng":"12.5359979","title":"rome"} ]
i want convert javascript array getting values. example:
myarray = [ [1, 1, 'this athens', 37.77994127700315,23.665237426757812, 'athens'] [2, 1, 'this rome', 41.9100711, 12.5359979, 'rome'] ]
i tried many solutions found here, didn't found solution give me array myarray
.
assuming :
var = [{"id":"1","map_id":"1","description":"this athens","lat":"37.77994127700315","lng":"23.665237426757812","title":"athens"},{"id":"2","map_id":"1","description":"this rome","lat":"41.9100711","lng":"12.5359979","title":"rome"}];
you can utilize array.prototype.map()
:
var myarray = a.map(function(e){ homecoming [e.id, e.map_id, e.description, e.lat, e.lng, e.title]; });
result:
[ ["1","1","this athens","37.77994127700315","23.665237426757812","athens"], ["2","1","this rome","41.9100711","12.5359979","rome"] ]
javascript arrays json
No comments:
Post a Comment