Abdul Majeed Abdul Majeed - 11 months ago 58
Javascript Question

Push is not working

After reading data with the help of for Each loop. Data is populating successfully.
I am trying to push objects in an array named test Data but it fails. Push is not working.
Below is my code.

data.content.forEach(function(column) {
var objects = {
ip: "",
user: "",
objects.ip = column.ip;
objects.user = column.username;
var d = new Date(column.created);
var a = d.toUTCString();
objects.date_created = a;
}, function(error){

Answer Source

if you see at line no 1 you declared an array $scope.testData = [];

so you need to use $scope.testData.push(objects)