AngularJS | angular.isArray() Function

The angular.isArray() Function in AngularJS is used to return TRUE if the reference is an array and FALSE if it is not an array.
Syntax:

angular.isArray(value)

Return value: Returns TRUE if the value is an array else it will return FALSE.

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

<html>
    <head>
        <title>angular.isArray()</title>
    <script src=
    </script>
    </head>
    <body ng-app="app" style="text-align:Center">
        <h1 style="color:green">GeeksforGeeks</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>

chevron_right


Output:
isarray

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <title>angular.isArray()</title>
    <script src=
    </script>
    </head>
    <body ng-app="app" style="text-align:Center">
        <h1 style="color:green">GeeksforGeeks</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 = 'GeeksforGeeks';
                $scope.name = values;
                $scope.isArray = angular.isArray(values)
            }]);
        </script>
    </body>
</html>

chevron_right


Output:
isarray



My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.