我正在尝试将值从一个数组推送到第二个数组,但每次输出第二个数组时,我都会得到一个空的'[]'输出
$scope.myArray = [];
$http.get("http://127.0.0.1/dbtest/init.php").then(function(response){
$scope.myData = response.data.records;
for(var i = 0; i < $scope.myData.length; i++){
$scope.myArray.push({
text: $scope.myData[i].id,
image: $scope.myData[i].url
});
}
console.log($scope.myData); //1st output this one works
});
console.log($scope.myArray); //2nd output shows empty array
这是我从http请求中得到的结果