Closed KaivnD closed 5 years ago
My guess is that it has a problem looping the Collection
because a collection is not an Array
. Could you try to push all those items into an array and then use the for … of …
loop?
I think we had a similar problem with a forEach loop.
Or we are missing a polyfill for Symbol.
@fabianmoronzirfas Thanks for reply
This Array
is not empty
for(let i = 0; i < layers.length; i ++) // And this loop works
I think the polyfill for Symbol is missing
Did you try to use the
for let item of …
With something other then a collection? The thing is the collection object has the property length but might not work with the other type of loop
Can you run a test like this:
const items = [];
for(let i = 0; i < layer.pathItems.length; i++){
items.push(layer.pathItems[i]);
}
for ( let path of items ) {
//do some stuff for this path
}
And tell me if the same error occurs?
@KaivnD ping
Related? #4
Sorry, I'm busy doing my work lately. I'm quite sure that layers is not empty in my code, the point is, I was trying to use for...of... loop to iterating my layers array , which is from app.activeDocument.layers in Illustrator. I just test the for...of... loop is not working, so I use for(let i =0; i < layers.length; i ++)
to iterating array instead, that's all.
Lately I've found another issue, I'll open another issue
It's not about the layers being empty it's about layers being a collection and not an array in the illustrator DOM.
That's why I asked you to run this test code where all the layers are stored in an actual array to see if the for … of … loop works.
If it works it's an illustrator problem if it doesn't it's my problem. :)
@fabianmoronzirfas Ok, I get it, let me test it
I run the test, @fabianmoronzirfas and yes , you are right about this, app.activeDocument.layers is not an actual array. So , there is no way to use this layers as a actual array ?
And I realize this issue is about the use of for..of..
statement , my intention is to use this statement in my code, but I've got error when use this statement for app.activeDocument.layers
, I never try the actual array. So I'm free to use this statement in my source code except something like app.activeDocument.layers
, problem solved! Thank you for your patience! @fabianmoronzirfas
Great. 👍🏽
Hi everybody! I've got a issue about for...of... loop in my code. Here is the things,
When I use for ... of loop , I got a an error like
Here is the code , which is translated, about for of loop in my source code