1 Reply Latest reply on Sep 11, 2017 11:38 AM by Bernd Alheit

    Javascript-Hi any insights on this please , comparing array of objects and picking the required one and checking for its value change ,this code is working but how it can be made to satsify all conditions

    harsh7
      I'll get array of objects "item", I have to filter out the latest object containing "Cluster deployment in progress" and then keeping
      a check on that same id conatining "Cluster deployment in progress" , when its status changes from "in-progress" to "success"
      So please help in making this piece of code to work on all conditions
      item = [
        {id:"59b6115432acd43347dd5b2b",
        notif_detail:"Cluster deployment in progress",
        notif_time:"2017-09-11T04:30:12.552Z",
        status:"in-progress"},
        {
        id:"59b6239e32acd43347dd5b57",
        notif_detail:"Cluster deployment in progress",
        notif_time:"2017-09-11T05:48:14.275Z",
        status:"in-progress"
        }
        ]
        
      solution:-
        this.subscription = this._userService.navItem$.subscribe(item =>
        this.item1 = item)
        console.log(this.item1)
        let clustProgress = this.item1.filter(e => e.notif_detail == "Cluster
        deployment in progress")
        console.log(clustProgress);
        let mostRecClustDep = clustProgress.sort(function (a, b) {
        return new Date(b.notif_time).getTime() - new Date(a.notif_time).getTime()
        })[0];
        console.log(mostRecClustDep)
        let result = this.item1.filter(e => e.id === mostRecClustDep.id);
        console.log(result)
        let resultstat = result.map(e => e.status)
        console.log(resultstat);
        if (resultstat[0] === "in-progress") {
        //Do something 
        } else {
        //Do something else
        }