Moderator: Paul Tuersley

Topic Author
Posts: 15
Joined: Sun Dec 10, 2006 10:23 pm

JS Array slice method

Thu Aug 27, 2015 9:18 pm

I was going nuts trying to work out why a script wasn't working. I was using the Javascript array object's slice method:
selectedLayers = app.project.activeItem.selectedLayers;
layerSlice=selectedLayers.slice(a, b);

But it was returning undefined. Am I doing something wrong or does array.slice() not work in AE?

I ended up building my own replacement:
function mySlice(inputArray, startIndex, sliceLength){
//this returns two arrays: first a slice of the original containing
//sliceLength elements from the input starting with startIndex
//and a second containing the rest of the original array
   sliceArray = [];
   for(var i=0; i < inputArray.length; i++){
      if((i < startIndex) | (i >= startIndex + sliceLength)){
      } else {
   return [sliceArray, outPutArray];

Who is online

Users browsing this forum: No registered users and 1 guest