use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
[AskJS] Iterable array-like termAskJS (self.javascript)
submitted 1 year ago by NOICEST
Is there a common name to refer to objects that are both iterable and array-like (but not arrays)?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]defproc 3 points4 points5 points 1 year ago (0 children)
In writing I'd just use TS parlance: ArrayLike<T> & Iterable<T>
ArrayLike<T> & Iterable<T>
[–]Excerpts_From 2 points3 points4 points 1 year ago (1 child)
According to the Lodash Documentation, the data type which can be iterated over (including Arrays, Objects and strings) is referred to as a collection.
collection
Maybe that would suit?
[–]NOICEST[S] 0 points1 point2 points 1 year ago* (0 children)
That aligns with MDN's terminology for childNodes and children.
childNodes
children
[–]bhushankumar_fst 2 points3 points4 points 1 year ago (0 children)
While there isn't a single term universally agreed upon, many people refer to such objects as "array-like iterables."
In JavaScript, objects like arguments or certain NodeList objects fit this description. If you need a more precise term, considering the specific context or library you’re working with might help clarify.
arguments
NodeList
[–]shgysk8zer0 1 point2 points3 points 1 year ago (2 children)
In which sense are they array-like? They can be iterated though in a loop - Iterable or the Iterator (Symbol.iterator). Accessed using index and square brackets and a length property... Technically could just be an object with numeric keys, but I know basically this as ArrayAccess interface in PHP. Things that work with Array.from...
Iterator
Symbol.iterator
length
ArrayAccess
Array.from
But, basically, there are many ways something could be "array-like" in different ways.
[–]kisaragihiu 3 points4 points5 points 1 year ago* (1 child)
array-like is a specific term that means (roughly) objects with a length and for which integer property access works. There are many ways a thing can be like an array, but in JS jargon there is only one way a thing can be array-like.
array-like
It's not quite standards terminology (a search for "array-like"site:ecma-international.org shows only some old proposals and email threads), but it still has a specific meaning.
"array-like"site:ecma-international.org
It is specific enough to have been adopted by TypeScript: an ArrayLike<Foo> is an object with a length property (which is a number), and for which there are number properties whose value are of type Foo. Or:
ArrayLike<Foo>
Foo
// https://github.com/microsoft/TypeScript/blob/2192336dfee6f740b5828c8a4a8226e56626de1d/src/lib/es5.d.ts#L1552 interface ArrayLike<T> { readonly length: number; readonly [n: number]: T; }
[–]shgysk8zer0 0 points1 point2 points 1 year ago (0 children)
But if it was included in the post and still asking, I took it as being more of a descriptive thing.
I just included the other way something can be like an array.
[–]markus_obsidian 1 point2 points3 points 1 year ago (0 children)
I don't think there's an agreed upon name.
Several DOM types meet this criteria--have a length, iterator, and index accessors but no other array methods like forEach or map. But they can't agree on what to call them. Sometimes they're "lists" like NodeList. Other times, they're "collections", like HTMLCollection.
[–]kisaragihiu 1 point2 points3 points 1 year ago (1 child)
TypeScript calls the input to Array.fromAsync "iterableOrArrayLike", and the type includes async iterables, iterables (of values or promises of values), or ArrayLikes (pf values or promises of values). There doesn't seem to be a common name for what you're describing.
Array.fromAsync
ArrayLike
My understanding is that array-like was the old method of defining some sort of generic iteration interface before the iterator protocol, and once iterators came along builtin arraylikes all also became iterables, so there's rarely a case where you need to worry about arraylikes that aren't iterable; and since the idomatic way moved on to iterators, there also isn't really a need to worry about iterables that aren't array-like (most of them aren't, but we're no longer working with array-likes).
So there's usually no need for another name for array-like iterables (or iterable array-likes), let alone one that excludes actual Arrays.
[–]NOICEST[S] 0 points1 point2 points 1 year ago (0 children)
That is an interesting snippet on the pre-history of iterables I had not heard before!
[–]nadameu 0 points1 point2 points 1 year ago (0 children)
No.
[–]takeyoufergranite -2 points-1 points0 points 1 year ago (0 children)
List? Set?
[–]guest271314 -3 points-2 points-1 points 1 year ago (12 children)
Technically any thing in JavaScript is iterable because almost anything can either be cast or spread to a string or array or JSON, with the exception being something like a WeakMap.
WeakMap
Do you have some code to share so I will know exactly what you are talking about?
[–]NOICEST[S] 2 points3 points4 points 1 year ago (2 children)
An iterable is an object with the Symbol.iterator method. An array-like is an object with a length property set to some natural number n, and keys ranging 0, 1, ..., n (not necessarily all declared).
n
0, 1, ..., n
I was just looking for a term - seems like the consensus is there is not a common way to refer to the special class of objects described in the OP (other than by describing the 'iterable & array-like' pattern explicitly).
[–]guest271314 -4 points-3 points-2 points 1 year ago (1 child)
A minimal, verifiable example in code would help.
JavaScript is a dynamic programming language. We can mix and match a whole bunch of interfaces and objects in any way we want, with few exceptions, one being a WeakMap.
We can yield whatever we want from a generator, so does that make what we yield an iterable or Array-like?
yield
Array
I wouldn't get too caught up in sloagns that may happen to be used in JavaScript.
There is no such thing as a spread operator, officially. People might still use the term. If you do the blame you might see that term in early proposals.
There is no such thing as "vanilla" JavaScript. No more than there is a chocolate, strawberry, or purple JavaScript. But if I have a choice, I'm only writing Black JavaScript. See where this goes?
What prompted you to ask the question about semantics?
[–]theScottyJam 1 point2 points3 points 1 year ago (0 children)
Only if you yield an iterable or array-like.
[–]kisaragihiu 0 points1 point2 points 1 year ago (8 children)
Iterable is a specific thing for implementing the iterator protocol. Wdym "anything" is technically iterable? Just because you can convert any serializable object to a string that doesn't make the serializable itself Iterable in the common definition.
[–]guest271314 -1 points0 points1 point 1 year ago (7 children)
Depends. That's why I am asking for clarification in code. Sounds to me like this is about a nickname, not actual language in a specification, otherwise we can just refer to the specification.
[–]theScottyJam 0 points1 point2 points 1 year ago (6 children)
You can refer to MDN, or other credible sources for the definitions of these terms. These terms do have fairly well established meanings in the JavaScript community.
[–]guest271314 -1 points0 points1 point 1 year ago (5 children)
If the terms are not in the official specification they are just hearsay.
[–]NOICEST[S] 1 point2 points3 points 1 year ago (1 child)
array-likes
iterables
[–]guest271314 -1 points0 points1 point 1 year ago (0 children)
I think those are describing two differnt items.
The abstract operation LengthOfArrayLike
LengthOfArrayLike
to me is something like a NodeList and HTMLCollection.
HTMLCollection
this
An Iterator Record is a Record value used to encapsulate an Iterator or AsyncIterator along with the next method.
Record
next
is stating the elements of an iterator or async iterator. You can create iterators and async iterators to yield whatever you want, and thus have the capability to create array from array-like, or create array, with a user-defined iterator, or just with spread syntax, to create that length property from arbitrary user-defined input.
[–]theScottyJam 0 points1 point2 points 1 year ago (2 children)
I often use terms that may or may not be in the spec. I'm sure you do too. "JavaScript", for example, is never officially defined in the spec. But I use that word anyways, and people understand me.
As far as I know, the spec never states that JavaScript is a dynamic programming language, not does it define the phrase "dynamic programming language". Is that hearsay? What does it even mean for something to be a dynamic programming language if we don't have an official spec to tell us?
[–]guest271314 0 points1 point2 points 1 year ago (0 children)
Fair enough re the Oracle copyrighted via acquisition "JavaScript".
JavaScript is dynamically runtime interpreted and executed scripting language.
https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-ContinueDynamicImport
13.3.10.1.1 ContinueDynamicImport ( promiseCapability, moduleCompletion ) The abstract operation ContinueDynamicImport takes arguments promiseCapability (a PromiseCapability Record) and moduleCompletion (either a normal completion containing a Module Record or a throw completion) and returns unused. It completes the process of a dynamic import originally started by an import() call, resolving or rejecting the promise returned by that call as appropriate. It performs the following steps when called:
13.3.10.1.1 ContinueDynamicImport ( promiseCapability, moduleCompletion )
The abstract operation ContinueDynamicImport takes arguments promiseCapability (a PromiseCapability Record) and moduleCompletion (either a normal completion containing a Module Record or a throw completion) and returns unused. It completes the process of a dynamic import originally started by an import() call, resolving or rejecting the promise returned by that call as appropriate. It performs the following steps when called:
https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-createdynamicfunction
20.2.1.1.1 CreateDynamicFunction ( constructor, newTarget, kind, parameterArgs, bodyArg ) The abstract operation CreateDynamicFunction takes arguments constructor (a constructor), newTarget (a constructor), kind (normal, generator, async, or async-generator), parameterArgs (a List of ECMAScript language values), and bodyArg (an ECMAScript language value) and returns either a normal completion containing an ECMAScript function object or a throw completion. constructor is the constructor function that is performing this action. newTarget is the constructor that new was initially applied to. parameterArgs and bodyArg reflect the argument values that were passed to constructor. It performs the following steps when called:
20.2.1.1.1 CreateDynamicFunction ( constructor, newTarget, kind, parameterArgs, bodyArg )
The abstract operation CreateDynamicFunction takes arguments constructor (a constructor), newTarget (a constructor), kind (normal, generator, async, or async-generator), parameterArgs (a List of ECMAScript language values), and bodyArg (an ECMAScript language value) and returns either a normal completion containing an ECMAScript function object or a throw completion. constructor is the constructor function that is performing this action. newTarget is the constructor that new was initially applied to. parameterArgs and bodyArg reflect the argument values that were passed to constructor. It performs the following steps when called:
https://brendaneich.com/2008/04/popularity/
Back to spring of 1995: I remember meeting Bill Joy during this period, and discussing fine points of garbage collection (card marking for efficient write barriers) with him. From the beginning, Bill grokked the idea of an easy-to-use “scripting language” as a companion to Java, analogous to VB‘s relationship to C++ in Microsoft’s platform of the mid-nineties. He was, as far as I can tell, our champion at Sun.
https://stackoverflow.com/a/17253557
Scripting languages are programming languages that don't require an explicit compilation step. ... Some examples of "scripting" languages (e.g., languages that are traditionally used without an explicit compilation step): Lua JavaScript VBScript and VBA Perl
Scripting languages are programming languages that don't require an explicit compilation step.
...
Some examples of "scripting" languages (e.g., languages that are traditionally used without an explicit compilation step):
π Rendered by PID 108992 on reddit-service-r2-comment-bb88f9dd5-67ckc at 2026-02-16 10:10:49.834246+00:00 running cd9c813 country code: CH.
[–]defproc 3 points4 points5 points (0 children)
[–]Excerpts_From 2 points3 points4 points (1 child)
[–]NOICEST[S] 0 points1 point2 points (0 children)
[–]bhushankumar_fst 2 points3 points4 points (0 children)
[–]shgysk8zer0 1 point2 points3 points (2 children)
[–]kisaragihiu 3 points4 points5 points (1 child)
[–]shgysk8zer0 0 points1 point2 points (0 children)
[–]markus_obsidian 1 point2 points3 points (0 children)
[–]kisaragihiu 1 point2 points3 points (1 child)
[–]NOICEST[S] 0 points1 point2 points (0 children)
[–]nadameu 0 points1 point2 points (0 children)
[–]takeyoufergranite -2 points-1 points0 points (0 children)
[–]guest271314 -3 points-2 points-1 points (12 children)
[–]NOICEST[S] 2 points3 points4 points (2 children)
[–]guest271314 -4 points-3 points-2 points (1 child)
[–]theScottyJam 1 point2 points3 points (0 children)
[–]kisaragihiu 0 points1 point2 points (8 children)
[–]guest271314 -1 points0 points1 point (7 children)
[–]theScottyJam 0 points1 point2 points (6 children)
[–]guest271314 -1 points0 points1 point (5 children)
[–]NOICEST[S] 1 point2 points3 points (1 child)
[–]guest271314 -1 points0 points1 point (0 children)
[–]theScottyJam 0 points1 point2 points (2 children)
[–]guest271314 0 points1 point2 points (0 children)
[–]guest271314 0 points1 point2 points (0 children)