Open In App

Lodash _.size() Method

Improve
Improve
Like Article
Like
Save
Share
Report

Lodash _.size() method gets the size of the collection by returning its length for the array such as values or the number of own enumerable string keyed properties for objects.

Syntax:

_.size(collection);

Parameters:

  • collection: This parameter holds the collection to inspect.

Return Value:

This method returns the collection size.

Example 1: In this example, we are printing the size of the given array by the use of the _.size() method.

javascript




// Requiring the lodash library
const _ = require("lodash");
 
// Original array and use _.size() method
let gfg = _.size([12, 14, 36, 29, 10]);
 
// Printing the output
console.log(gfg);


Output:

5

Example 2: In this example, we are printing the size of the given object by the use of the _.size() method.

javascript




// Requiring the lodash library
const _ = require("lodash");
 
// Original array and use _.size() method
let gfg = _.size({ 'p': 1, 'q': 2, 'r': 5 });
 
// Printing the output
console.log(gfg);


Output:

3

Example 3: In this example, we are printing the size of the given string by the use of the _.size() method.

javascript




// Requiring the lodash library
const _ = require("lodash");
 
// Original array and use _.size() method
let gfg1 = _.size('geeksforgeeks');
let gfg2 = _.size('computer science');
 
// Printing the output
console.log(gfg1, gfg2);


Output:

13, 16


Last Updated : 25 Oct, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads