Copy link to clipboard
Copied
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);
I believe the version of JavaScript AE uses only supports indexOf for strings, not arrays.
Dan
Copy link to clipboard
Copied
I believe the version of JavaScript AE uses only supports indexOf for strings, not arrays.
Dan
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Yes, and this one is from 1999, now we have 2015 ![]()
Copy link to clipboard
Copied
I often add functionality to the built in Javascript objects via their prototype, including indexOf:
/**
* Array.indexOf - Like String.indexOf() but checks for an object in an array
*
* @method
* @param {Object} obj object to find in the array
* @returns {Number} location in the array of the object, or -1 if not found
*/
if(!Array.prototype.indexOf) {
Array.prototype.indexOf = function(obj) {
for(var i=0; i<this.length; i++) {
if(obj===this) {
return i;
}
}
return -1;
};
}
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more