jquery - How to make an array of arrays from a javascript object? -
i have object this:
{"peppermint":"50","chocolate":"50"}
i want turn this:
[['peppermint', '50']['chocolate', '50']]
using jquery map function so:
var array = $.map(data, function(value, index) { return [value]; });
gives me without keys:
["50", "50"]
you have return inner array both values in , has embedded in array. need level of array because jquery doc $.map
:
a returned array flattened resulting array.
so, need code working snippet:
var data = {"peppermint":"50","chocolate":"50"}; var array = $.map(data, function(prop, key) { return [[key, prop]]; }); document.write(json.stringify(array));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
Comments
Post a Comment