Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 计算数组中的对象数_Angularjs_Arrays_Object_Count - Fatal编程技术网

Angularjs 计算数组中的对象数

Angularjs 计算数组中的对象数,angularjs,arrays,object,count,Angularjs,Arrays,Object,Count,这就是我所做的 $scope.data.months = []; angular.forEach(response, function (value, key) { $scope.data.months.push({'month':value}); }); 日志(响应)如下所示 Array[3] 0 : "April 2017" 1 : "May 2017" 2 : "June 2017" 月份数组结果的console.log如下所示 Array[0

这就是我所做的

$scope.data.months = [];    
angular.forEach(response, function (value, key) {
      $scope.data.months.push({'month':value});
  });
日志(响应)如下所示

Array[3]
 0
 :
 "April 2017"
 1
 :
 "May 2017"
 2
 :
 "June 2017"
月份数组结果的console.log如下所示

Array[0]
0 : Object
  month : "April 2017"
__proto__
:
Object
1 : Object
  month : "May 2017"
__proto__
:
Object
2 : Object
  month : "June 2017"
__proto__
:
Object
我有两个问题

->第一个是为什么它会显示数组[0]而不是数组[3],因为这个数组中有三个对象

->第二个问题是如何计算月数 我认为,如果第一个问题得到解决,那么第二个问题将从第一个问题得到解决


我是角js的新手,我做错了什么,请引导我正确的方向

关于你的第一个问题。如果控制台显示0数组并打开它显示其中的项,则这是一个未解决的承诺问题。换句话说,当您调用第一个console.log时,承诺尚未解决,但同时解决它将显示您打开时返回的数组


对于第二个问题,我想可能会对您有所帮助。

在您记录时,array.lengh会给您($scope.data.months.length)带来什么?您能告诉我响应是什么吗?我希望它是一个数组。是的,当然是一个minAlso,你能告诉我你到底在哪里写控制台吗。logIt返回0@PaulThomasGC