I have the array in the following pattern:
[["abc","def"],["dss","ddd"]]
I need to convert it into an array of json objects:
[{"wf":"abc","sb":"def"},{"wf":"dss","sb":"ddd"}]
How would I do this?
Try this
var data= [["abc","def"],["dss","ddd"]];
var json = data.map(function (value, key) {
return {
"wf": value[0],
"sb": value[1]
}
});
console.log(json);
console.log(JSON.stringify(json)); // need string
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.