Lodash _.isArguments() method
What you’ll learn
- How
_.isArguments(value)spots real Arguments objects. - Why arrays, plain objects, and copied argument lists usually return
false. - The difference between the legacy
argumentsbinding and rest-parameter arrays. - When modern rest syntax replaces the need for this check.
Prerequisites
Know that non-arrow functions expose an arguments object and that array-like values are not always Arrays.
- You can run short snippets inside plain
function () { … }bodies. - You can open Try-it labs in the browser.
Overview
_.isArguments answers a narrow question: “Is this value the engine’s Arguments object?” That matters when you write helpers that accept variadic inputs and must branch between Arguments-like collections and real arrays.
True Arguments only
Designed for the legacy binding inside ordinary functions—not arbitrary plain objects.
Not Array.isArray
Arrays fail this check even when they mirror argument indexes.
Rest replaces many uses
(...args) gives a real Array, sidestepping Arguments-specific detection.
Syntax
_.isArguments(value) - value: any value to test.
- Returns:
trueifvalueis an Arguments object; otherwisefalse.
Classic function: real Arguments object
Inside an ordinary function, arguments is what _.isArguments is built to recognize.
import isArguments from "lodash/isArguments";
function demo() {
return isArguments(arguments);
}
demo(1, 2, 3); // true After Array.from or spread: no longer Arguments
Copying into a real Array drops the Arguments branding—use Array.isArray or accept Arrays directly instead.
import isArguments from "lodash/isArguments";
function demo() {
var arr = Array.from(arguments);
return isArguments(arr);
}
demo(1, 2); // false Rest parameters, arrays, and plain objects
Rest bundles parameters into an Array. Ordinary arrays and objects are never classified as Arguments.
import isArguments from "lodash/isArguments";
function withRest(...items) {
return isArguments(items);
}
withRest(1); // false
isArguments([]); // false
isArguments({ 0: "a", length: 1 }); // false 📋 _.isArguments vs other checks
| Check | Typical use |
|---|---|
_.isArguments(x) | Detect the engine Arguments object from legacy functions. |
Array.isArray(x) | True only for real Arrays (including rest-parameter bundles). |
_.isPlainObject(x) | Plain objects created via Object; not Arguments. |
Pitfalls to avoid
No local arguments
Arrow functions inherit lexical scope and do not define arguments; avoid assuming it exists.
Expecting true after conversion
[...arguments], slice, and Array.from yield Arrays—_.isArguments becomes false.
Variadic helpers
Prefer documenting “pass an Array” or using rest parameters so callers rarely need Arguments detection.
❓ FAQ
Summary
- Purpose: identify true Arguments objects from classic functions.
- Not for: generic array-like duck typing—Arrays and copied lists fail.
- Next: explore more on Lodash _.isArray().
The legacy arguments binding is an array-like object—not an Array instance—so it lacks methods like map until you convert it (for example with Array.from), which also removes the Arguments object tag that _.isArguments looks for.
6 people found this page helpful
