angular.Object.size

Description

Determines the number of elements in an array, the number of properties an object has, or the length of a string.

Note: This function is used to augment the Object type in Angular expressions. See angular.Object for more information about Angular arrays.

Usage

angular.Object.size(obj, ownPropsOnly);

Parameters

Returns

{number}

The size of obj or 0 if obj is neither an object nor an array.

Example

 <script>
   function SizeCtrl() {
     this.fooStringLength = angular.Object.size('foo');
   }
 </script>
 <div ng:controller="SizeCtrl">
   Number of items in array: {{ [1,2].$size() }}<br/>
   Number of items in object: {{ {a:1, b:2, c:3}.$size() }}<br/>
   String length: {{fooStringLength}}
 </div>
 it('should print correct sizes for an array and an object', function() {
   expect(binding('[1,2].$size()')).toBe('2');
   expect(binding('{a:1, b:2, c:3}.$size()')).toBe('3');
   expect(binding('fooStringLength')).toBe('3');
 });