How to iterate an array of objects and group the property values by their key name?
问题 I have an array of objects named data , like so: data = [{"timeslot":"7pm-8pm","Monday":60,"Tuesday":55}, {"timeslot":"8pm-9pm","Monday":70,"Tuesday":60}, {"timeslot":"9pm-10pm","Monday":40,"Tuesday":37}] I want to get from this array three new arrays, like so: timeslot = ["7pm-8pm", "8pm-9pm", "9pm-10pm"] monday = [60, 70, 40] tuesdat = [55, 60, 37] Effectively grouping the data values by the data property name to which they belong. Here is my Javascript var timeslot = []; var monday = [];