How can an array of objects be grouped based on keys using vanilla JavaScript, especially when dealing with a large number of records like 10000? Here is a sample object to illustrate:
[
{
company: "TATA",
car: "TATA Indica",
color: "Blue"
},
{
company: "TATA",
car: "TATA Indica",
color: "Black"
},
{
company: "TATA",
car: "Safari",
color: "Blue"
},
{
company: "Suzuki",
car: "",
color: ""
}
]
The desired output should look like this:
{
"company": ["TATA", "Suzuki"],
"car": ["TATA Indica", "Safari"],
"color": ["Blue", "Black"]
}