Search code examples
javascriptslickgrid

Array of objects gives undefined


so I have this slickgrid function which adds changed values in a cell to an object.

grid.onCellChange.subscribe(function (e,args) { 
                 //console.log('arguments',args.item);
               
                editedRows.push(args.items)
                 //console.log('arrayrows',editedRows)
             });
    
  }

when I try to add the Object to array editedrows it gives undefined.

the object looks like this :

   arguments {hours: "6U", Total_inspection: 1234, Total_losses: 12345}

I though you could just push an object into an array and create a array of objects ? what am I doing wrong

thanks in advance


Solution

  • Your arguments does not have an items property, it has others like hours etc. You just push undefined into the array above, since argumnets.items is undefined.

    If what you wnat to do is to push the object as it is into an array just push itself:

    editedRows.push(args)
    

    But if you want actually a different thing like pushing all the keys, values, or both into an array then you need one of the Object static methods like keys, values or entries.