function groupByProperties(arr) {
const result = {};
arr.forEach(item => {
Object.keys(item).forEach(key => {
if (!result[key]) {
result[key] = [];
}
result[key].push(item[key]);
});
});
return result;
}
// 示例用法
const data = [
{ name: 'Alice', age: 25, city: 'New York' },
{ name: 'Bob', age: 30, city: 'Paris' },
{ name: 'Charlie', age: 35, city: 'London' }
];
const groupedData = groupByProperties(data);
console.log(groupedData);