Struggling to determine the most efficient method of assigning array indices to an object with boolean values. Currently employing the following approach:
let arr = [{t:1, te: "aa"}, {t:2, te: "aa"},{t:2, te: "aa"} ];
let obj = {}
arr.map((item, index) => (obj[index] = false));
console.log(obj)
If dealing with an array containing 200 objects, it would look like {0: false, 1:false, ....}
Considered using Array.reduce()
, however unable to achieve desired result and consistently encountering:
var result = Object.assign(...arr.map(k => ({ [k]: true })));
{
[object Object]: false
}
Is there a more concise way to accomplish this task in just one line?