Appending to an array of dictionaries


    Mar 02 2021 | 11:16 pm
    Hello!
    I'm using a dict object to store data about midi notes as an array of dictionaries:
    { "Notes" : [ { "Pitch" : 38, "Velocity" : 77, "Start" : 0.0, "End" : 0.065021 } , { "Pitch" : 42, "Velocity" : 100, "Start" : 0.330751, "End" : 0.068439 } , { "Pitch" : 42, "Velocity" : 96, "Start" : 0.66747, "End" : 0.040532 } ] }
    From following this very useful page about the dict object I found that I can append dictionaries to an array of dictionaries by sending the [dict] object two messages: first (append Notes *), which creates a new entry, and then (setparse Notes[5] Pitch: 46 Velocity: 127. Start: 0. End: 1).
    This works, but I have to know the length of the current array before I append any new value. Does anyone know if there is a way to append a dictionary to the end of an array of dictionaries without having to know what index to set it at? If anyone knows how to do this with Max or Javascript, that would be amazing!
    Let me know if you want me to explain more/better...

    • May 10 2021 | 4:12 am
      Well, if you were simply using a standard JavaScript array instead of a dictionary, then you could just use Array.prototype.push. In fact, you could make a JavaScript array of dictionaries.