I get a JSON data with this format:
{
key1: val1,
key2: val2,
key3: val3,
key4: val4,
..
}
Now I want to change it to another format in Javascript:
[
{key: "key1", value: value1},
{key: "key2", value: value2},
{key: "key3", value: value3},
{key: "key4", value: value4},
...
]
Is there some libraries that can do this? Or I have to write a function?
Please give me some tips! Thanx!
var newObject = Object.keys(originalObject).map(function(k) {
return { key: k, value: originalObject[k] };
});
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.