Check array with day object

I have an array of object,

DayEffort:[{     Description: null     Effort: 2     EffortDate: "2019-05-20T00:00:00"     day:Sunday     Status: "In Progress"    },            {      Description: null     Effort: 1.5     EffortDate: "2019-05-22T00:00:00"     Day : Tuesday      Status: "In Progress"     },     {      Description: null     Effort: 1.5     EffortDate: "2019-05-23T00:00:00"     Day : Thursday     Status: "In Progress"  }] 

which contain day property, if day is sunday, it needs to push on zero index of new array, Monday is on 1st index, if not matching push null value,

Excepted result:

NewArray : [ 0:{Description: null Effort: 2 EffortDate: "2019-05-20T00:00:00" day:Sunday Status: "In Progress"}, 1: null, 2: {Description: null Effort: 2 EffortDate: "2019-05-20T00:00:00" day:Tuesday Status: "In Progress"}, 3: null, 4: {Description: null Effort: 2 EffortDate: "2019-05-20T00:00:00" day:Thursday Status: "InProgress"}, 5: null, 6: null, ] 

Tried,

var DayArray = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday', 'Saterday'];   for(var k = 0 ; k < DayArray.length; k++){                        for(var m = 0; m < DayEffort.length; m++){                                                   if(DayArray[k] == DayEffort[m].day){                              NewArray.push(DayEffort[m]);                           }                          else{                              NewArray.push(null);                                                                                      }                       }                                        } 

Please help me,

Professor Asked on October 26, 2020 in Android langue.
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.