Convert array to object keys

You can use Array.prototype.reduce()and Computed property names

let arr = ['a','b','c'];
let obj = arr.reduce((ac,a) => ({...ac,[a]:''}),{});
console.log(obj);

var target = {}; ['a','b','c'].forEach(key => target[key] = "");

You can use Object.assign property to combine objects created with a map function, please take into account that if values of array elements are not unique the latter ones will overwrite previous ones

const array = Object.assign({},...["a","b","c"].map(key => ({[key]: ""})));
console.log(array);

try with Array#Reduce

const arr = ['a','b','c'];
const res = arr.reduce((acc,curr)=> (acc[curr]='',acc),{});
console.log(res)

Tags:

Javascript