Lodash – size method

Lodash - size method

Syntax Of Lodash size method

_.size(collection)

The Lodash size method gets the size of the collection by returning its length for array-like values or the number of its 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

Next Topic – Click Here

This Post Has 2 Comments

Leave a Reply