Search code examples
vectorxpagesxpages-ssjs

How to read a specific item in a vector?


I have a viewScope "selection" which is a vector. I would like to be able to read a specific elementh (third in this case) I thought dooing it with an iterator like this , but it just gives me all the elements instead of the third...

var i = 0;
for (var it = viewScope.selection.iterator();it.hasNext();i++ ) {
  if (i == 3){
    sessionScope.example="item "+i+"="+it.next();
  }
}

Solution

  • Maybe I don't really understand your question, but you can get the third element via index, i.e. like

    viewScope.selection[2]
    

    or

    viewScope.selection.get(2)