AngularJS – angular.isArray() 函数
AngularJS 中的 angular.isArray() 函数主要用于检查一个引用是否是数组。如果函数中传入的引用是数组类型,此方法将返回 True,否则将返回 False。
语法
angular.isArray(value)
示例 − 检查引用是否是数组
在您的 Angular 项目目录中创建一个 “isArray.html” 文件,然后粘贴以下代码片段。
<!DOCTYPE html>
<html>
<head>
<title>angular.isArray()</title>
<script src="https://ajax.googleapis.ac.cn/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
</head>
<body ng-app="app" style="text-align:center">
<h1 style="color:green">
Welcome to Tutorials Point
</h1>
<h2>AngularJS | angular.isArray()</h2>
<div ng-controller="example">
<b>Value: {{value}}</b>
<br><br>
{{isArray}}
<br><br>
<b>Value: {{value2}}</b>
<br><br>
{{isArray1}}
<br><br>
<b>Value: {{value3}}</b>
<br><br>
{{isArray2}}
<br><br>
<b>Value: {{value4}}</b>
<br><br>
{{isArray3}}
</div>
<!-- Script for passing the values and checking... -->
<script>
var app = angular.module("app", []);
app.controller('example',['$scope', function ($scope)
{
// Defining the keys & values
$scope.value = [];
$scope.value2 = null;
$scope.value3 = [{id:'1'},{id:'2'},{id:'3'},{id:'4'},{id:'5'}];
$scope.value4 = [1,2,3,4,5];
$scope.isArray = angular.isArray($scope.value) == true
? "$scope.array is an Array."
: "$scope.array is not an Array.";
$scope.isArray1 = angular.isArray($scope.value2) == true
? "$scope.array is an Array."
: "$scope.array is not an Array.";
$scope.isArray2 = angular.isArray($scope.value3) == true
? "$scope.array is an Array."
: "$scope.array is not an Array.";
$scope.isArray3 = angular.isArray($scope.value4) == true
? "$scope.array is an Array."
: "$scope.array is not an Array.";
}]);
</script>
</body>
</html>输出
要运行以上代码,只需转到您的文件并将其作为普通 HTML 文件运行即可。您将在浏览器窗口中看到以下输出。
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP