Ask coding questions

← Back to all posts
How to make faster way of clones in JS
h
Coder2195Text (35)

look:

I have these clones in this list:

for example:

clones = [new clone(), new clone(),new clone(), new clone(), new clone(),new clone(), new clone(), new clone(),new clone()]

Instead of iterating through every clone to move forward (forward() function), is there
Is there a faster way to do this?

Comments
hotnewtop
SixBeeps (5047)

Iterating is the only way of doing this.
There are faster and cleaner ways of iterating other than just the normal for-loop. The forEach loop should work for you use case:

clones.forEach(clone => clone.forward());