JS Array slice method
Posted: August 27th, 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:
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:
Code: Select all
selectedLayers = app.project.activeItem.selectedLayers;
layerSlice=selectedLayers.slice(a, b);
I ended up building my own replacement:
Code: Select all
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
outPutArray=[];
sliceArray = [];
for(var i=0; i < inputArray.length; i++){
if((i < startIndex) | (i >= startIndex + sliceLength)){
outPutArray.push(inputArray[i]);
} else {
sliceArray.push(inputArray[i]);
}
}
return [sliceArray, outPutArray];
}