我正在以这种格式获得一些价值
[["first"],["second"],["third"]]
我希望得到
{"first","second","third"}
我应该在javascript中做什么?
答案 0 :(得分:0)
这是非法的:{"first","second","third"}
对象必须是键值对的映射。你能做到的最好的就是:
{`first`: null, `second`: null, `third`: null}
var arr2d = [["first"], ["second"], ["third"]];
var arrFlat = arr2d.reduce(function(a, b) {
return a.concat(b);
});
var obj = {};
for (var i = 0; i < arrFlat.length; i++) {
obj[arrFlat[i]] = null;
}
console.log(obj);