Skip to main content
vlceversa
Known Participant
April 18, 2015
Answered

Array indexOf() Reference Error?

  • April 18, 2015
  • 1 reply
  • 2880 views

Hello,

I have these simple code lines and on line 20 I'm getting the error in the comment but I cant find the problem in my code

  var directions      = [0,1,2,3];

  var lockedDirection = 0;

  var lastDirection   = 2; // sample code

  switch (lastDirection) {

  case 0:

       lockedDirection = 2;

       break;

  case 1:

       lockedDirection = 3;

       break;

  case 2:

       lockedDirection = 0;

       break;

  case 3:

       lockedDirection = 1;

       break;

  };

  var a = directions.indexOf(lockedDirection); // ReferenceError: Function directions.indexOf is undefined

  directions.splice(a, 1);

This topic has been closed for replies.
Correct answer Dan Ebberts

I believe the version of JavaScript AE uses only supports indexOf for strings, not arrays.

Dan

1 reply

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
April 18, 2015

I believe the version of JavaScript AE uses only supports indexOf for strings, not arrays.

Dan

vlceversa
vlceversaAuthor
Known Participant
April 18, 2015

Ok, so AE JavaScript != JavaScript? Thats a bad implementation. If Adobe wants us to use JavaScript for Scripting then they should implement it the right way . I found a Solution here, had to implement the function myself. Array.prototype.indexOf() - JavaScript | MDN

Btw, do I violate any Copyright with implementing this function in my Script?

Dan Ebberts
Community Expert
Community Expert
April 18, 2015

As of the CS6 Scripting Guide, ExtendScript supports the 3rd edition of the ECMA-262 standard (which appears to be at edition 5.1 now).

Dan