AngularJS angular.isArray()函数

angular.isArray()函数
【AngularJS angular.isArray()函数】在AngularJS中用于返回
true
如果引用是数组, 并且
false
如果不是数组。
语法如下:

angular.isArray(value)

返回值:如果该值是一个数组, 则返回TRUE, 否则将返回FALSE。
范例1:
< html > < head > < title > angular.isArray()< / title > < script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js" > < / script > < / head > < body ng-app = "app" style = "text-align:Center" > < h1 style = "color:green" > lsbin< / h1 > < h2 > angular.isArray()< / h2 > < div ng-controller = "geek" > < b > Sorting Algos:< / b > < div ng-repeat = "i in sort" > {{i.name}}< / div > < br > < br > isArray: {{isArray}} < / div > < script > var app = angular.module("app", []); app.controller('geek', ['$scope', function ($scope) { $scope.sort = []; var values = [ { name: 'Merge sort' }, { name: 'Quick sort' }, { name: 'Bubble sort' } ]; if (angular.isArray(values)) { $scope.isArray = true; angular.forEach(values, function (value, key) { $scope.sort.push(value) }) } }]); < / script > < / body > < / html >

输出如下:
AngularJS angular.isArray()函数

文章图片
范例2:
< !DOCTYPE html> < html > < head > < title > angular.isArray()< / title > < script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js" > < / script > < / head > < body ng-app = "app" style = "text-align:Center" > < h1 style = "color:green" > lsbin< / h1 > < h2 > angular.isArray()< / h2 > < div ng-controller = "geek" > < b > Input: < / b > {{name}} < br > < br > < b > isArray:< / b > {{isArray}} < / div > < script > var app = angular.module("app", []); app.controller('geek', ['$scope', function ($scope) { var values = 'lsbin'; $scope.name = values; $scope.isArray = angular.isArray(values) }]); < / script > < / body > < / html >

输出如下:
AngularJS angular.isArray()函数

文章图片

    推荐阅读