JUCE Javascript does not support array key/value pairs?

You can add bracket subscription to access properties of objects pretty easy.

In juce_Javascript.cpp, modify the ArraySubscript class (starting with line 408):

var getResult (const Scope& s) const override
{
    var arrayVar (object->getResult (s)); // must stay alive for the scope of this method

    if (const Array<var>* array = arrayVar.getArray())
    {
        return (*array) [static_cast<int> (index->getResult (s))];
    }
    else if (const DynamicObject* obj = result.getDynamicObject())
    {
        const String name = index->getResult(s).toString();
        
        return obj->getProperty(Identifier(name));
    }


    return var::undefined();
}

void assign (const Scope& s, const var& newValue) const override
{
    var arrayVar (object->getResult (s)); // must stay alive for the scope of this method

    if (Array<var>* array = arrayVar.getArray())
    {
        const int i = index->getResult (s);
        while (array->size() < i)
            array->add (var::undefined());

        array->set (i, newValue);
        return;
    }
    else if (DynamicObject* obj = result.getDynamicObject())
    {
        const String name = index->getResult(s).toString();
                 
        return obj->setProperty(Identifier(name), newValue);
    }

    Expression::assign (s, newValue);
}

(This is a rather quick hack, there may be some edge cases where the behavior is not standard conform).

Now you can use the Javascript conform array subscript for objects:

var dynamics = {};
dynamics["pp"] = 30;
alert(dynamics["pp"]);
1 Like