Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Values of array

  • Posted by Pierre-alain Lécroart on May 14, 2020 at 11:06 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

    Andrei Popa replied 6 years, 3 months ago 2 Members · 3 Replies
  • 3 Replies
  • Andrei Popa

    May 14, 2020 at 3:15 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.

  • Pierre-alain Lécroart

    May 15, 2020 at 9:11 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.

  • Andrei Popa

    May 16, 2020 at 9:49 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.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy