The Wayback Machine - https://web.archive.org/web/20251222133352/https://www.geeksforgeeks.org/angular-js/angularjs-angular-isarray-function/
  • Full Stack Development40% Off
  • AngularJS angular.isArray() Function

    Last Updated : 6 Sep, 2022

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

    Parameter:

    • value: It specifies the reference to check the value.

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

    Example 1: This example describes the basic usage of angular.isArray() Function in AngularJS.

    HTML
    <!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">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>
    

    Output:

    isarray

     Example 2: This is another example that describes the usage of angular.isArray() Function in AngularJS.

    HTML
    <!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">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>
    

    Output:

    isarray

    Comment