I am getting some value in this format
[["first"],["second"],["third"]]
and i want to get
{"first","second","third"}
what should i do in javascript?
This is illegal: {"first","second","third"}
An object must be a mapping of key-value pairs. The best you can achieve is this:
{`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);
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.