Invokes an iteratee n times and returns an array of the results. The iteratee receives one argument: the zero-based index. Part of Lodash Util since 0.1.0 (stable — not deprecated).
Note: Default iteratee is _.identity, so _.times(3) yields [0, 1, 2].
Syntax
Call _.times. Start with this line.
Lodash
_.times(n, [iteratee=_.identity])
Call
What it does
_.times(n, [iteratee=_.identity])
Primary signature.
_.times(...)
Call the util helper.
Prefer import times from "lodash/times" when you want a smaller bundle.
Library declarations
Lodash
_.times(n, [iteratee=_.identity])
Parameters
Parameter
Description
n
Required. How many times to invoke the iteratee
iteratee
Optional. Called with (index); default _.identity
Return Value
Return Value
Description
*
Array of each invocation’s return value
Lodash Examples
Example 1 — Official: String Iteratee
Convert each index to a string — the docs’ canonical demo.
Unique. Each call to _.uniqueId("row_") bumps a counter.
Prefix. Every id starts with row_.
Array. You get three distinct strings ready for list keys or placeholders.
Compatibility
Browser & Runtime Support
_.times is a Lodash Util helper since 0.1.0. It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.
✓ Stable · Lodash 0.1.0+
_.times()
Available in [email protected] full builds and the lodash/times modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.
100%With Lodash 0.1+
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
_.timesLodash 0.1.0+
Bottom line: Safe for production once Lodash is loaded. Prefer import times from "lodash/times" for smaller bundles. Use it when you need an array of n computed results keyed by index.
Frequently Asked Questions
_.times(n, iteratee) invokes iteratee n times with the index 0, 1, …, n − 1, and returns an array of each return value. Official: _.times(3, String) → ['0','1','2'].
One argument: the zero-based index. There is no collection element — only the count index.
_.identity. So _.times(3) returns [0, 1, 2] — each index echoed back.
Lodash returns []. The iteratee is never called. No manual guard is required for empty counts.
_.range builds a number sequence from start/end/step. _.times runs a function n times and collects results. Use range for numeric arrays; times when each step computes a value.
Use a for loop when you need break/continue, await per iteration, or heavy imperative control. Use _.times for a compact array-of-results expression.