I iterate over an array of objects, all have a date property. The conditional value that I set inside the loop to compare the date of the object with today's date should only take care of a few objects in the array that I want to keep because of the old date, however this condition deletes all the objects in the array for some reason.
The getTime () function does not work. getTime removes everything from the array. As I tried here:
constructor ( public navCtrl: NavController, public modalCtrl: ModalController, public loading: LoadingController, public popoverCtrl: PopoverController, public getPostSrvc: getPostsService) { this.listOfEvents = []; let that = this; function getPostsSuccess (listOfEventsObject) { for (var i in listOfEventsObject) { if(listOfEventsObject[i].date.getTime() < Date.now()){ that.listOfEvents.push(listOfEventsObject[i]); }
UPDATE My solution:
export class Home { listOfEvents: Array<any> = []; parseDate: number; today : number; constructor ( //constructor stuff ){ for (var i in listOfEventsObject) { that.today = Date.now(); that.parseDate = Date.parse(listOfEventsObject[i].date); if( that.parseDate > that.today){ that.listOfEvents.push(listOfEventsObject[i]); }
source share