size
Modified on Thu, 24 Aug 2023
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 Value | Description |
---|---|
Number | Returns the size of the collection, either its length for arrays or the count of its own enumerable properties for objects. |
Sample
Example | Result | Description |
---|---|---|
size([1, 2, 3, 4, 5]) | 5 | Returns '5' because the collection is an array with 5 elements. |
size({ name: 'John', age: 30 }) | 2 | Returns '2' because the collection is an object with 2 own enumerable properties. |
To view all Object methods, click here.
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article