or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-lodash--map

The lodash method _.map exported as a module for creating arrays of values by running each element through an iteratee function.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/lodash.map@4.6.x

To install, run

npx @tessl/cli install tessl/npm-lodash--map@4.6.0

index.mddocs/

Lodash Map

Lodash Map provides the _.map method as a standalone module for creating arrays of values by running each element in a collection through an iteratee function. It supports both arrays and objects, with multiple iteratee formats including functions, object shorthands, and property paths.

Package Information

  • Package Name: lodash.map
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install lodash.map

Core Imports

var map = require('lodash.map');

For ES6 modules:

import map from 'lodash.map';

Basic Usage

var map = require('lodash.map');

// Basic array transformation with function
function square(n) {
  return n * n;
}

map([4, 8], square);
// => [16, 64]

// Object transformation
map({ 'a': 4, 'b': 8 }, square);
// => [16, 64] (iteration order is not guaranteed)

// Property extraction using string shorthand
var users = [
  { 'user': 'barney' },
  { 'user': 'fred' }
];

map(users, 'user');
// => ['barney', 'fred']

Capabilities

Map Function

Creates an array of values by running each element in collection through iteratee. The iteratee is invoked with three arguments: (value, index|key, collection).

/**
 * Creates an array of values by running each element in collection through iteratee
 * @param {Array|Object} collection - The collection to iterate over
 * @param {Function|Object|string} [iteratee=_.identity] - The function invoked per iteration
 * @returns {Array} Returns the new mapped array
 */
function map(collection, iteratee);

Parameters:

  • collection (Array|Object): The collection to iterate over. Can be an array, array-like object, or plain object
  • iteratee (Function|Object|string, optional): The function invoked per iteration. Defaults to identity function if not provided

Returns:

  • Array: Returns the new mapped array containing the results of applying the iteratee to each element

Iteratee Function Signature: When using a function as iteratee, it receives three arguments:

  • value: The current element value
  • index|key: The index of the element (for arrays) or property key (for objects)
  • collection: The collection being iterated over

Iteratee Shorthand Options:

  • Function: Custom transformation function (value, index, collection) => transformedValue
  • String: Property path shorthand like 'user' extracts that property from each element
  • Object: Matches object shorthand like {active: true} filters elements matching the object
  • Undefined/null: Uses identity function, effectively creating a shallow copy

Usage Examples:

var map = require('lodash.map');

// Function iteratee
function square(n) {
  return n * n;
}
map([4, 8], square);
// => [16, 64]

// Object collection
map({ 'a': 4, 'b': 8 }, square);
// => [16, 64] (iteration order is not guaranteed)

// String property path shorthand
var users = [
  { 'user': 'barney' },
  { 'user': 'fred' }
];
map(users, 'user');
// => ['barney', 'fred']

// Object matching shorthand
var data = [
  { 'name': 'apple', 'organic': true },
  { 'name': 'banana', 'organic': false },
  { 'name': 'carrot', 'organic': true }
];
map(data, { 'organic': true });
// => [true, false, true]

// Identity function (shallow copy)
map([1, 2, 3]);
// => [1, 2, 3]

// Array-like objects
map('hello', function(char) { return char.toUpperCase(); });
// => ['H', 'E', 'L', 'L', 'O']

Performance Notes:

  • Uses optimized arrayMap implementation for arrays
  • Uses baseMap implementation for objects and array-like objects
  • Integrates with lodash's iteratee system for shorthand support via getIteratee

Compatibility:

  • Works with arrays, array-like objects (like strings, arguments), and plain objects
  • Maintains compatibility with lodash's iteratee shorthand syntax
  • Follows lodash's iteration order conventions (arrays maintain order, objects do not guarantee order)