• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Two arrays, values less than 20 from one array delete the same index numbers from second array

Community Beginner ,
Feb 04, 2018 Feb 04, 2018

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
TOPICS
Scripting

Views

682

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 04, 2018 Feb 04, 2018

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Feb 04, 2018 Feb 04, 2018

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".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 05, 2018 Feb 05, 2018

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...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

I dont know, it looks unrelated.

In which sense you "don't get the right result" ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

LATEST

I've made a mistake. It should be keyTimes instead of keyTimes[i-1]. Thank you for your time Xavier. Appreciate that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines