Is there a way to transform an array of objects into an object with one of the properties as a key?
What is the best method to achieve this conversion?
const data = [
{
id: "first",
name: "Product 1",
type: "selection"
},
{
id: "second",
name: "Product 2",
type: "text"
},
{
id: "third",
name: "Product 3",
type: "csv"
}
]
Desired output:
{
first: { name: 'Product 1', type: 'selection' },
second: { name: 'Product 2', type: 'text' },
third: {name: 'Product 3', type: 'csv' },
}
Can this be achieved using the ARRAY.REDUCE METHOD?