I am trying to come up with the way to loop through an array of values, save each value as a key and assign a 'true' boolean value for each key.
The goal is to create the following object:
{
"arrayValue" : true,
"anotherArrayValue" : true,
"arrayValueAsWell" : true
}
I am doing:
var objectToCreate = {};
let myArray = ["arrayValue", "anotherArrayValue", "arrayValueAsWell"]
let myArrayConverted = myArray.forEach((prop,index) => objectToCreate[prop] = true)
and getting:
{
0 : "arrayValue",
1 : "anotherArrayValue",
2 : "arrayValueAsWell"
}
objectToCreate[prop] = true;— there's no need to create a capital-B Boolean object.{ arrayValue: true, anotherArrayValue: true, arrayValueAsWell: true}isn't that what you want ?varandlet?myArrayConvertedwill beundefined.Array.prototype.forEach()returnsundefined.