javascript - 如何在 for 循环中进行反转?

标签 javascript angularjs

我有这个Js方法,但我无法实现反向循环

$scope.organizeByMonth = function () {    
    for (var i in $scope.incidents) {

        var month = new Date($scope.incidents[i].upload_date).getMonth();    
        if (!monthIncidents[month]) {

            monthIncidents[month] = {    
                name: $scope.months[month],
                incidents: []
            };
        }
        var incident = $scope.incidents[i];    
        incident.index = i;    
        monthIncidents[month].incidents.push(incident);
    }
};

如何反向显示相同的对象:/

最佳答案

您不能使用 for in 语法进行反向循环 - 这也没关系。 JavaScript 中的对象是无序的。

关于javascript - 如何在 for 循环中进行反转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31526387/

相关文章:

javascript - CSS 选择器最后一个子元素与最后一个元素

javascript - jQuery如何选择div中的所有节点文本

javascript - 使用具有变换原点中心的滚轮在鼠标点上放大/缩小图像。需要帮助计算

javascript - Angular js 选项卡应用程序

angularjs - 错误 : No template found for MyAppComponent

angularjs - 指令要求中的问号

javascript - 实时刷新 Rails View

php - 验证粘贴在字段中的脚本

javascript - 为什么 $scope.someArray.push 不是传递给 $q.promise 上的 .then 的有效函数

javascript - 如何在 AngularJS 中使用 CKEditor 上传图像?