After seeing this question raised multiple times, I am determined to find a solution. In my current project, I am tasked with displaying a list of orders and implementing a filter by date functionality. However, I keep encountering an error when trying to push each filtered order into a new array:
"TypeError: filteredOrders.push is not a function"
I've attempted to adjust the syntax for pushing objects into arrays but have had no success so far. Each order is returned as an Object, and I am looping through an array of objects. Here's a clearer example of my code:
data: function () {
return {
isFilterShown: false,
IsOrderDetailShown: false,
selectedDateFrom: new Date(),
selectedDateTill: new Date(),
}
},
methods: {
applyFilter: function () {
let dateFrom = this.selectedDateFrom;
let dateTill = this.selectedDateTill;
let filteredOrders = Array;
this.orders.forEach(function (order) {
if (order.createdAt >= moment(dateFrom).format('DD-MM-Y') && order.createdAt <= moment(dateTill).format('DD-MM-Y')) {
console.log(order.createdAt, order);
return order;
}
filteredOrders.push(order);
})
// this.orders = this.filteredOrders;
this.isFilterShown = false;
},
Console screenshot: https://i.stack.imgur.com/8Neb0.png