Skip to main content
femkeblanco
Legend
April 22, 2020
Answered

Could someone please explain how to use the index() method?

  • April 22, 2020
  • 2 replies
  • 2122 views

Could someone please explain how to use the index() method?  The reference says:


app.activeDocument.pathItems.index(itemKey)

Gets an element from the collection.  itemKey is a string or number.


I presumed that it would be similar to getByName(), but returns an object by an array's index

instead.  This doesn't seem to be the case.  For example, if I want to reference "pathItems[2]" in the example below, I get an error.


So what actually is "itemKey" and how does one use the index() method? 

 

Thanks in advance. 

 

var path0 = activeDocument.pathItems.add();  // pathItems[2]
path0.name = "path0";
var path1 = activeDocument.pathItems.add();  // pathItems[1]
path1.name = "path1";
var path2 = activeDocument.pathItems.add();  // pathItems[0]
path2.name = "path2";

alert(activeDocument.pathItems[2].name);  // works, i.e. alerts "path0"

var xxx = activeDocument.pathItems.index(2);  // doesn't work
alert(xxx.name);

 

This topic has been closed for replies.
Correct answer CarlosCanto

hmm...Interesting, I've never used Index() so I never realized it doesn't work.

do you need to use it or are you just curious?

My guess is that Index is probably an obsolete function that existed in an ancient version of the scripting engine and they forgot to remove it from the Reference.

 

Index is not listed in the OMV so officially it doesn't exist now

 

on the other hand, it is still current in the VBS engine. That's why I think it did exist in javascript at some point in its early life.

 

2 replies

CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
Community Expert
April 24, 2020

hmm...Interesting, I've never used Index() so I never realized it doesn't work.

do you need to use it or are you just curious?

My guess is that Index is probably an obsolete function that existed in an ancient version of the scripting engine and they forgot to remove it from the Reference.

 

Index is not listed in the OMV so officially it doesn't exist now

 

on the other hand, it is still current in the VBS engine. That's why I think it did exist in javascript at some point in its early life.

 

femkeblanco
Legend
April 24, 2020

Thank you both. 

 

I don't need to use it.  I was just curious. 

 

 

renél80416020
Inspiring
April 23, 2020

Bonjour Blanco,

L'index le plus petit [0] est au premier plan (objet.zOrder(ZOrderMethod.BRINGTOFRONT);)

xxx = activeDocument.pathItems[0];

Ne pas utiliser

 

activeDocument.pathItems.index (2)