JavaScript forEach 跳出当前循环

Js 中 forEach 不能使用 continue, break 跳出循环spa

可使用 if 语句控制,或者 return . (return true/false) // return --> 相似 for 循环的 continue it


//全选io

            $scope.selectAll = function(){function

                var all = $scope.all;angular

                angular.forEach($scope.items, function (item, index) {select

                    if(item.hasInventory){循环

                        item.checked = all;scope

                        if(all)co

                            os[index] = item;new

                    }else{

                        return;    //跳出当前循环、或者不写 else 

                    }

                });

                if(!all)

                    os = new Array();

            }