我有一个包含对象的数组。现在我想将数组切片为仅包含与特定属性值匹配的对象的新数组。
理想情况下,新的数组名称应该动态创建。
原始数组如下所示:
specificSlotButtonArray = [
{slotStarttime:"06:00:00", slotTimespan:1},
{slotStarttime:"09:00:00", slotTimespan:1},
{slotStarttime:"12:00:00", slotTimespan:2},
{slotStarttime:"15:00:00", slotTimespan:2},
{slotStarttime:"18:00:00", slotTimespan:3}
];
新数组应如下所示:
timespan1 = [
{slotStarttime:"06:00:00", slotTimespan:1},
{slotStarttime:"09:00:00", slotTimespan:1}
]
timespan2 = [
{slotStarttime:"12:00:00", slotTimespan:2},
{slotStarttime:"15:00:00", slotTimespan:2}
]
timespan3 = [
{slotStarttime:"18:00:00", slotTimespan:3}
]
如果可能的话,我想避免 IE 和其他一些旧浏览器不支持的 javascript 语法/函数。
我已经尝试过与reduce()
and slice()
,但没有找到解决办法。