I want to extract all objects from an array and combine them into a single object. Here is the current array data:
userData = [
{"key":"firstName","checked":true},
{"key":"lastName","checked":true},
{"key":"userName","checked":false},
{"key":"email","checked":false}
]
and I am using the following code snippet:
let results = {
data: userData.forEach((k) =>({ ...k}))
}
console.log (results)
The current output looks like this:
[
{"key":"firstName","checked":true},
{"key":"lastName","checked":true},
{"key":"userName","checked":false},
{"key":"email","checked":false}
]
However, my desired result is as follows:
{"firstName":{"key":"firstName", "checked":false},
"lastName":{"key":"lastName", "checked":false},
"username":{"key":"username", "checked":false}
"email":{"key":"email","checked":false},
}