I have some problem with my code when I create an array in this loop its repeat same as previous and not correct
getTimeShiftPermission = (data) => {
const toDay = moment().format('[today] dddd')
let newData = []
if (data) {
let newItem = {}
data.map((i, index) => {
if (i.start !== '00:00' || i.end !== '23:59') {
console.log('index', index, i)
newItem.start = i.start
newItem.end = i.end
newItem.day = moment.weekdays(index)
newData.push(newItem)
} else if (i.start === "" || i.end === "") {
return []
}
})
console.log('newData', newData)
return newData
} else {
return []
}}
and its result
0: {start: "03:02", end: "14:51", day: "Thursday"}
1: {start: "03:02", end: "14:51", day: "Thursday"}
.maponly for iteration. Mapping returns an array already, you don't have to manually build it. Use.forEachor an actual loop for iteration.