Set keys without knowing the structure of the dictionary in js. Help!

bonesash's icon
Max Patch
Copy patch and select New From Clipboard in Max.

I built a patch to write keys of any depth into a dictionary. The trick is to check if the dictionary alreday exists; if not, create a new one, set it as a value of a key and refer to the key in a dict obj with: "name u*****(name of the key)" in the first inlet of dict. Now, i tried to code it in javascript, because im not safisfied with the result and its easy to do loops in contrast to max, but im not able to refer to an dict object only to copy it.

autowatch = 1;
outlets = 1;

function set(){

    var what = new Array ();
    var keys = new Array ();
    var bol = true;
    what = arrayfromargs(arguments);
    var dict = new Dict(what [0]);

    for (i=1; i

        if (bol){
            bol = false;
            if (typeof dict == "object"){
                if (dict.getkeys () + "" != "null"){
                    keys = dict.getkeys ();
                    if (typeof keys == "string")
                        keys = new Array(keys);
                    for (j=0; j < keys.length;j++){
                        if (what [i] + "" == keys [j] + ""){
                            bol = true;
                            break;
                        }
                    }
                }
            }
        }

        if (!bol){
                dict.set (what[i] + "", new Dict);
        }

            dict == (dict.get(what [i] + ""));
    }

    dict.set (what[what.length - 2] + "", what[what.length - 1]);
    outlet (0, "true");

}
`