Declaring variables issue
I have just started to learn JavaScript, and I have been using VBA before (thanks to the advice and help of @DilliamWowling and @CarlosCanto , let me enter the world of JS). This forum is a good place to start!!
Here is a short piece of code from @Silly-V
var targetObjects = doc.layers.getByName("Target Position").pathItems;
var objectsToMove = [
doc.layers.getByName("To move aligned objects").layers[0].pathItems[0],
doc.layers.getByName("To move aligned objects").layers[1].pathItems[0],
doc.layers.getByName("To move aligned objects").layers[2].pathItems[0]
];
for (var i = 0; i < objectsToMove.length; i++) {
objectsToMove[i].top = targetObjects[i].top;
objectsToMove[i].left = targetObjects[i].left;
}
I want to ask a simple question about the following method of declaring variables:
var objectsToMove = [
doc.layers.getByName("To move aligned objects").layers[0].pathItems[0],
doc.layers.getByName("To move aligned objects").layers[1].pathItems[0],
doc.layers.getByName("To move aligned objects").layers[2].pathItems[0]
];
I tried to refer to the relevant topics on this forum, but I still didn't find the answer. I'm curious about this declaration method. It seems that this variable is defined with a constant value pathitems [0] ? When it is objectsToMove[i], what value is the objectsToMove ? Is it below?
doc.layers.getByName("To move aligned objects").layers[0].pathItems[i],
doc.layers.getByName("To move aligned objects").layers[1].pathItems[i],
doc.layers.getByName("To move aligned objects").layers[2].pathItems[i]
I really don't understand why it can be like this?
And what value is the objectsToMove.length ?Is it layers [0]. pathitems length? or layers[1].pathItems. length? or layers[2].pathItems. length? Or the sum of them? If the number of pathitems in each layer is different, can it be executed correctly?
Many thanks in advance for your time and advice!
