Skip to content
Agents tracked: 440 Downloads (7d): 202M down 19.5% GitHub stars: 10.4M Releases (7d): 607 Agent status: 3 with issuesSince last limit reset: Claude 28d · Codex 0d Updated Oct 21, 2026

Iterate collections with Lodash

Lodash collection methods accept arrays, objects and strings alike, so one call style covers all three.

All Lodash examples Lodash: usage and stats

Iterate collections with Lodash: screenshot of the example below running
The code below, running in Chromium on our server (Oct 12, 2026). Press Run to see it live and change it.

How it works

  1. One API for three shapes. _.map runs on an array, on a plain object (getting each value and key) and on a string (getting each character). [1]
  2. Walk an object. _.forEach(prices, (price, item) => ...) visits every key of the object and prints a line for each. [1]
  3. Filter by property. _.filter(tasks, { done: false }) uses an object as the test and keeps tasks whose done matches. [1]

Run and edit it

It runs in your browser, in a sandboxed frame that cannot see this site; the packages load from esm.sh only after you press Run.

import _ from 'lodash';

// Arrays
const nums = [1, 2, 3, 4];
console.log('array map x10:', JSON.stringify(_.map(nums, (n) => n * 10)));

// Objects: callback gets (value, key)
const prices = { apple: 1.2, bread: 2.5, cheese: 6 };
console.log('object forEach:');
_.forEach(prices, (price, item) => console.log(`  ${item.padEnd(7)} $${price.toFixed(2)}`));
console.log('object map:', JSON.stringify(_.map(prices, (price, item) => `${item}=${price}`)));

// Strings: iterated character by character
console.log('string map:', _.map('lodash', (ch) => ch.toUpperCase()).join('-'));

// Filter with an object as the test
const tasks = [
  { title: 'Write docs', done: true },
  { title: 'Fix bug', done: false },
  { title: 'Ship release', done: false },
];
const open = _.filter(tasks, { done: false });
console.log('open tasks:', open.map((t) => t.title).join(', '));
console.log('open count:', open.length, 'of', tasks.length);
Ctrl/⌘ + Enter runs

Free for signed-in members, with a daily limit. Describe the change in plain words; the new code runs only in your browser.

Swap the word in the string example and the per-letter output changes. Code written by AgentGid [1].

Checked Oct 12, 2026: it starts without errors in Chromium with lodash 4.18.1. Needs WebGL.

More Lodash examples

Default values with _.defaults Split arrays with _.partition Read nested values with _.at Compose functions with Lodash

Sources

  1. Lodash website

Explanations written by AgentGid from the official docs; the numbers in brackets point here. The code marked "written by AgentGid" is ours and free to copy.

Building something with Lodash? Ask AgentGid →