A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/lodash-_-invokemap-method/ below:

Lodash _.invokeMap() Method - GeeksforGeeks

Lodash _.invokeMap() Method

Last Updated : 03 Sep, 2024

Lodash's _.invokeMap() method calls a specified method at a given path for each element in a collection, returning an array of results. Additional arguments can be passed using the args parameter.

Syntax:
_.invokeMap( collection, path, args );
Parameters:

Return Value: This method returns the array of results.

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

javascript
// Requiring the lodash library 
const _ = require('lodash');

// Original array 
let obj = [[6, 2, 8], [2, 1, 0]];

// Using the _.invokeMap() method
let gfg1 = _.invokeMap(obj, 'sort');

// Printing the output 
console.log(gfg1);

Output:

[ [ 2, 6, 8], [ 0, 1, 2 ] ]

Example 2: In this example, we are spliting the given array by the use of the lodash _.invokeMap() method.

javascript
// Requiring the lodash library 
const _ = require('lodash');

// Original array 
let obj = [628, 210];

// Using the _.invokeMap() method 
let gfg1 = _.invokeMap(obj, String.prototype.split, '');

// Printing the output 
console.log(gfg1);

Output:

[ [ '6', '2', '8'], [ '2', '1', '0' ] ]

Example 3: In this example, we are spliting the given array by the use of the lodash _.invokeMap() method.

javascript
// Requiring the lodash library 
const _ = require('lodash');

// Original array 
let obj = ['srqp', 'tuvw'];
let obj1 = [['c', 'b', 'a'], ['f', 'e', 'd']];

// Using the _.invokeMap() method
let gfg = _.invokeMap(obj, String.prototype.split, '');
let gfg1 = _.invokeMap(obj1, 'sort');

// Printing the output 
console.log(gfg, gfg1);

Output:

[ [ 's', 'r', 'q', 'p'], [ 't', 'u', 'v', 'w' ] ]
[ [ 'a', 'b', 'c'], [ 'd', 'e', 'f' ] ]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4