Abdul Majeed Abdul Majeed - 20 days ago 5
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.

$scope.testData=[];
data.content.forEach(function(column) {
var objects = {
ip: "",
user: "",
date_created:""
};
objects.ip = column.ip;
objects.user = column.username;
var d = new Date(column.created);
var a = d.toUTCString();
objects.date_created = a;
testData.push(objects);
});
$scope.safeApply();
}, function(error){
console.log(error);
});

Answer

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

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

Comments