Lodash - size method


Advertisements

Syntax

_.size(collection)

Gets the size of collection by returning its length for array-like values or the number of own enumerable string keyed properties for objects.

Arguments

  • collection (Array|Object|string) − The collection to inspect.

Output

  • (number) − Returns the collection size.

Example

var _ = require('lodash');

var result = _.size([1, 2, 3]);
console.log(result);
 
result = _.size({ 'a': 1, 'b': 2 });
console.log(result);
 
result = _.size('pebbles');
console.log(result);

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

3
2
7
lodash_collection.htm
Advertisements