JS Array slice method

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
Posts: 21
Joined: December 10th, 2006, 10:23 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:

Code: Select all

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:

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
	sliceArray = [];
	for(var i=0; i < inputArray.length; i++){
		if((i < startIndex) | (i >= startIndex + sliceLength)){
		} else {
	return [sliceArray, outPutArray];
Post Reply