Description

Use this function to get the size of a collection. It returns the length for array-like values or the number of its own enumerable string-keyed properties for objects.

Syntax

size(collection)

Returns

Return ValueDescription
NumberReturns the size of the collection, either its length for arrays or the count of its own enumerable properties for objects.

Sample

ExampleResultDescription
size([1, 2, 3, 4, 5])5Returns '5' because the collection is an array with 5 elements.
size({ name: 'John', age: 30 })2Returns '2' because the collection is an object with 2 own enumerable properties.

To view all Object methods, click here.

See Also