Why is "arguments" a pseudo-array (array-like object) in JavaScript, but not just array? I think it happend historically, but what is the reason? Also why DOM-collections are pseudo-arrays. Does anybody know or at least have some guesses?
Asked
Active
Viewed 233 times
0
-
More info here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments – Ed Lucas Feb 20 '20 at 19:56
1 Answers
1
If you need arguments
as an array (for map(), etc.), it's easy enough to convert using the spread syntax:
let args = [...arguments];

Ed Lucas
- 5,955
- 4
- 30
- 42
-
I know. Also I can use `Array.from()` and `rest operator`, but my question about the reason. Why `arguments` is pseudo-array. It's more historical question, but I really interested in that. – Sergei Martianov Feb 20 '20 at 20:02
-
@SergeiMartianov Found an answer for you: https://stackoverflow.com/questions/3242485/why-isnt-a-functions-arguments-object-an-array-in-javascript – Ed Lucas Feb 24 '20 at 01:17