目前,我的JSON对象如下所示:
[
["GB", "gib", "gigabyte", "gigabytes"],
["MB", "mib", "megabyte", "megabytes"],
["Television", " Televisions", " TV", " TVs"],
["tryouts", "tryout", "tests", "test", "trial", "experiment"],
["football", "soccer", "Fussball"]
];
我最后想看到的是一个新的对象,看起来像这样:
[
{
synonyms: "GB, gib, gigabyte, gigabytes"
},
{
synonyms: "MB, mib, megabyte, megabytes"
},
{
synonyms: "Television, Televisions, TV, TVs"
},
{
synonyms: "tryouts, tryout, tests, test, trial, experiment"
},
{
synonyms: "football, soccer, Fussball"
}
];
任何帮助是极大的赞赏。
最佳答案
您可以使用Array.prototype.join()轻松地做到这一点:
var output = [];
for (var i = 0; i < input.length; i++) {
output.push({
synonyms: input[i].join(', ');
});
}
您发布的第一个数组的位置称为
input
。