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();

            }

相關文章
相關標籤/搜索