A RetroSearch Logo

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

Search Query:

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

Lodash _.map() Method - GeeksforGeeks

Lodash _.map() Method

Last Updated : 22 Aug, 2024

Lodash _.map() method creates an array of values by running each element in the collection through the 'iteratee'. Many methods are guarded to work as iteratees for methods like _.every(), _.filter(), _.map(), _.mapValues(), _.reject(), and _.some() methods.

Syntax:
_.map(collection, iteratee)
Parameters: Return Value:

This method returns the new mapped array.

Example 1: In this example, we have used the _.map() method on an array and do iteration while using function square.

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

// Original array 
let array = _.map([5, 18]);

// Use of _.map() method
let mapped_array = 
    _.map(array, function square(n) {
    return n * n;
})

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

Output:

[ 25, 324 ]

Example 2: In this example, we have used the _.map() method on an object and doing iteration while using function square.

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

// Original array 
let array = _.map({ 'x': 14, 'y': 28 });

// Use of _.map() method
let mapped_array = 
    _.map(array, function square(n) {
    return n * n;
})

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

Output:

[ 196, 784 ]


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