I am basically looking for a quick way to do this in javascript:
let arr = [{key: "alpha", value: "2", property1: "some"},{key:"beta", value:"3", property1: "extra", property2: "property"},{key: "gamma", value: "4"}];
let obj = someFunction(arr);
// WANTED RESULT:
//obj is now { "alpha" : { value: "2", property1: "some" }, "beta" : {value: "3", property1: "extra", property2: "property",} , "gamma": {value: "4"} }
Each object in the array can have more properties, and different ones, except for key.
Edit: This is what I have done. It still leaves a property on the objects, and I am not sure if this/looping is the most efficient way.
tempObj = {};
for (let i = 0; i < arr.length; i++) {
tempObj[arr[i].key] = arr[i];
}
//this will give this answer, close enough to what I want:
//{ alpha: {key: "alpha", value: "2", property1: "some"}, beta: key:"beta", value:"3", property1: "extra", property2: "property", gamma: {key: "gamma", value: "4"} }