如何从这种样式转换
(4) [{…}, {…}, {…}, {…}]
0: {program_id: "646", title: "Straight No Chaser", short_description: "Underground Hip Hop", description: "Funky sounds from the hip-hop diaspora.", start_time: "00:00",day : "Tuesday"}
1: {program_id: "1167", title: "Jazz Boulevard", short_description: "Classic jazz, blues, world, and acid jazz.", description: "CanCon friendly ... award-winning weekly syndicate…classic jazz tracks, blues, world, and acid jazz.", start_time: "04:00", day : "Tuesday", …}
2: {program_id: "1167", title: "Jazz Boulevard", short_description: "Classic ja", description: "CanConasdasd sd", start_time: "04:00", day : "Friday", …}
为此
{Sunday: Array(14), Monday: Array(18), Tuesday: Array(17), Wednesday: Array(19), Thursday: Array(19), …}
Friday: (19) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Monday: (18) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Saturday: (17) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Sunday: (14) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Thursday: (19) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Tuesday: (17) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Wednesday: (19) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
__proto__: Object
第一种样式已经具有每个对象的特定日期
我尝试过此方法,但是它没有提供相同的格式
const arrayToObject = (array, keyField) =>
array.reduce((obj, item) => {
obj[item[keyField]] = item
return obj
}, {})
const favouritesWithDaysAsObject = arrayToObject(favs, "day")