Skip to content

for .. in loop for Array is causing errors when Array.prototype is extended #1653

@molda

Description

@molda

On this line

for (const hname in hostnames) {
the for...in loop is used which causes an error when Array.prototype is extended since it iterates over the added methods.

Changing the for...in to for...of fixes the issue.

The framework i use Total.js framework v4 is extending the Array prototype by many useful methods.

Example without Total.js:

% node
Welcome to Node.js v20.10.0.
Type ".help" for more information.
> for (const a in [1]) console.log(a)
1

Example with Total.js:

Welcome to Node.js v20.10.0.
Type ".help" for more information.
> require('total4')
> for (const a in [1]) console.log(a)
0
take
first
toObject
last
quicksort
trim
skip
findAll
findValue
findItem
remove
wait
async
random
limit

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions