Create an array of numbers in the given range

List the integers from min to max inclusive.

JavaScript Version 1.0.0 · MIT · .md

create-an-array-of-numbers-in-the-given-range.js
function range({ min, max }) { return Array.from({ length: max - min + 1 }, (_, i) => min + i); }

Input & expected output

Input

{
  "min": 1,
  "max": 5
}

Expected output

[
  1,
  2,
  3,
  4,
  5
]

The edge case

Input

{
  "min": 3,
  "max": 3
}

Expected output

[
  3
]

Know the limits

  • The lab requires min ≤ max and at most 1,000 numbers before allocating.

The function above is the implementation used by the lab. The lab validates JSON types and caps size before execution; include equivalent validation when accepting untrusted input in your application.

Source & maintenance

Based on Create an array of numbers in the given range from the original 1loc collection by Nguyen Huu Phuoc, with jonrandy, Tsvika10. Copyright (c) 2020 phuoc-ng. MIT licensed.

Uses Array.from with a length; validates the range size before allocating. Original MDX retained as inert source evidence.

Maintained by Oveyon. Original source commit: 14b481cf60df. This edition’s file: contents/create-an-array-of-numbers-in-the-given-range.mdx in akamind/1loc, commit 0a77f131b22d. Read the license.

Local fixture scope · Node.js 22.23.2 · reviewed October 28, 2026. No external service is required.

Keep exploring

Type two or more characters. Try “duplicate”, “webhook” or “retry”.