Copy link to clipboard
Copied
Hi guys,
I have two arrays:
var keyTimes = new Array(1,2,3,4,5);
var keyValues = new Array (30,10,5,25,15);
I want to find numbers less then 20 in keyValues
and delete the same index numbers from keyTimes
array.
So, the keyTimes
array should look like this:
keyTimes = (1,4);
Thanks
Copy link to clipboard
Copied
This is working in javascript, but it's not working in extendscript:
const keyTimes = [1, 2, 3, 4, 5],
keyValues = [30, 10, 5, 25, 15];
const arr = keyTimes.filter((v, i) => keyValues[i] >= 20 );
console.log(arr)
Copy link to clipboard
Copied
That's "normal". Extendscript is missing much of modern javascript.
Array.prototype.filter doesnt exist there, and function expressions as in the filter argument are not recognized.
You need rewrite it "the old way".
Copy link to clipboard
Copied
Thank you Xavier,
I've came up with this solution:
var keyValues = [30, 10, 5, 25, 15],
keyTimes = [1, 2, 3, 4, 5];
for (var i = keyTimes.length -1; i >= 0; i--)
if(keyValues<20){
keyTimes.splice(keyTimes[i-1],1);
}
alert(keyTimes);
And I'm getting keyTimes = (1,4);
But, as you know the time in AE is not in frames but in seconds, so in real life my keyTimes are like this: 0.3213213, 0.45689789, 1.456546456, 2.456456456 etc. And with these values I don't get the right result. What could be a problem? I'm getting those values from 'Convert Audio to Keyframes', so I have value every keyframe. Thanks for your help...
Copy link to clipboard
Copied
I dont know, it looks unrelated.
In which sense you "don't get the right result" ?
Copy link to clipboard
Copied
I've made a mistake. It should be keyTimes instead of keyTimes[i-1]. Thank you for your time Xavier. Appreciate that.