I have this array
[ 0:'a', 1:'b', 2:'c']
I want convert this array to an object
{ 'a': true, 'b': true, 'c': true }
What is the best way ?
I have this array
[ 0:'a', 1:'b', 2:'c']
I want convert this array to an object
{ 'a': true, 'b': true, 'c': true }
What is the best way ?
array.reduce((acc, value) => {
acc[value] = true;
return acc;
})
Have a look at source
You could map entries from the array and get an object.
var array = ['a', 'b', 'c'],
result = Object.fromEntries(array.map(k => [k, true]));
console.log(result);