ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Values of array

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Pierre-Alain Lécroart
Values of array
on May 14, 2020 at 11:06:11 am

Hi !

Sorry for the noob question, I can't find a function that works to get all the values of an array

myArray = {
"a":1,
"b":2
};


If I do that :
alert(Object.keys(myArray));
I get "a,b"

When I do that
alert(Object.values(myArray));
I get an error "Function Object.values is undefined"

How do I get "1,2" ?

Thanks a lot


Return to posts index

Andrei Popa
Re: Values of array
on May 14, 2020 at 3:15:42 pm

That is an object. An array looks like this myArray = [1,2,3] and you access its values like this myArray[1].
How do you want to get the values of your object? As a string in this format "1,2"? If yes, try this:

function getValues(object){
var values = [];
for (var i in object) {
values.push(object[i]);
}
return values.join(",");
}

alert(getValues(myArray));


Andrei
My Envato portfolio.


Return to posts index

Pierre-Alain Lécroart
Re: Values of array
on May 15, 2020 at 9:11:06 pm

Sorry I don't know why I was so focused on the wrong idea that this was an array an not an object.
Thanks a lot for your solution ! ☺
So the idea is to push all the object values to an array.

Maybe it's because I'm a begginer but I don't really get why there is a "Object.keys" method that works in AE and the "Object.values" method don't.


Return to posts index


Andrei Popa
Re: Values of array
on May 16, 2020 at 9:49:18 am

I don't have an Object.keys on my version of after effects. I use AE 2020.
It may be that you have a different version or maybe you have some sort of library that extendet "Object" with a .keys function. You can check that by either

alert(Object.toSource())

or

$.writeln(Object.toSource())

When i run either one of these 2 functions, i only get (function Object() { [native code] } ), which means that my Object class does not have any new functions added to it.

Andrei
My Envato portfolio.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]