
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
AngularJS isArray Function
The angular.isArray() function in AngularJS basically checks if a reference is an Array or not. This method will return True if the reference passed inside the function is an Array type, else it will return False.
Syntax
angular.isArray(value)
Example − Check if the reference is an Array or not
Create a file "isArray.html" in your Angular project directory and copy-paste the following code snippet.
<!DOCTYPE html> <html> <head> <title>angular.isArray()</title> <script src="https://ajax.googleapis.com/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>
Output
To run the above code, just go to your file and run it as a normal HTML file. You will see the following output on the browser window.
Advertisements