[Vuejs]-Array Push only pushing last value of array

0πŸ‘

βœ…

In the .push i used "Object.assign({}, ”)
This works for me.

updatePersonnelTime() {
    console.log("updatePersonnelTime", this.time);
    var newtime = this.time;
    newtime.controlDateTime = new Date();
    if(!this.currentJob.time){
        this.currentJob.time = [];
    }
    for (let i=0; i < this.selected.length; i++){
        newtime.employeeID = this.selected[i];
        console.log('this.selected[i]: ', this.selected[i]);
        
// added 'Object.assign in the push
        this.currentJob.time.push(Object.assign({}, newtime)); 
        console.log('this.time: ', this.currentJob);
        
    }
    this.updateJob();
    this.timeRows = this.currentJob.time
    
},

Leave a comment