I would like to convert an array that looks like this:
['foo', 'bar', 'baz']
to an object that looks like this:
{
foo: true,
bar: true,
baz: true,
}
In most languages you would have some form of fill(keys, value) function:
var array = ['foo', 'bar', 'baz'];
var object = fill(array, true);
// object = { foo: true, bar: true, baz: true}
But in JS I can only find one for numeric keys using a range, not a list of keys. Is there a fill function that will do exactly that?
.reduce(). (I'm not so sure there's such a.fill()method in "most" languages.)Object.fromEntries(array.map(x => [x,true]))