A newer version of Max is available. Click here to access the latest version of the Max documentation

The Dict Object

The Dict Object

The Dict object in JS is a companion to the dict object you create in a Max patcher. It provides the ability to access structured data (a dictionary) associated with a name.

Dict Constructor

var d = new Dict("name")

If no name is provided as an argument then a unique name will be generated for the dictionary.

The following properties mirror the attributes of the same name from the Max dict object. See the dict reference for more details.

Dict Properties

name [symbol]

Access or set the name of a dict object as a property of the dict object

quiet [boolean] (default: false)

The quiet property functions the same as the @quiet attribute to dict in Max. It suppresses many errors or warnings if set to true.

Dict Methods

append

Arguments

key [symbol]
value [list]

Add values to the end of an array associated with the specified key.

clear

Erase the contents of the dictionary, restoring to a clean state.

clone

Arguments

name [symbol]

Make a clone of the incoming dictionary.

contains

Arguments

key [symbol]

Return a 0 or 1 indicating the specified key exists (or doesn't) in the dictionary.

freepeer

Frees the dictionary data from the native c peer, which is not considered by the JavaScript garbage collector, and may consume lots of memory until the garbage collector decides to run based on JS allocated memory. Once called, the dict object is not available for any other use.

get

Arguments

key [symbol]

Return the value associated with a key.

getkeys

Return a list of all the keys in a dictionary.

getnames

Return a list of all the dictionaries that currently exist.

getsize

Return the number of values associated with a key.

gettype

Return the type of the values associated with a key.

parse

Arguments

dictionary [string]

Replace the content of a dictionary with a JSON or Max dictionary formatted string.

pull_from_coll

Arguments

coll-name [symbol]

Pull the content of a named coll object into the dictionary.

push_to_coll

Arguments

coll-name [symbol]

Push the dictionary's content into a named coll object. The keys in the dictionary will become the indices in the coll, and the values for those indices the values of the dictionary's keys.

readany

Arguments

filename [symbol]

Read the dictionary contents from a file.

remove

Arguments

key [symbol]

Remove a key and its associated value from the dictionary.

replace

Arguments

key [symbol]
value [list]

Set the value for a key to a specified value, creating heirarchy.

set

Arguments

key [symbol]
value [list]

Set the value for a key to a specified value.

setparse

Arguments

key [symbol]
value [list]

Set the value for a key to dictionary content defined using JSON.

writeagain

Open a save dialog to write the dictionary contents to a file.

stringify

Return the content of the dictionary as a JSON string.

import_json

Arguments

filename [symbol]

Read a file from disk in the JSON format.

export_json

Arguments

filename [symbol]

Write a file to disk in the JSON format.

import_yaml

Arguments

filename [symbol]

Read a file from disk in the YAML format.

export_yaml

Arguments

filename [symbol]

Write a file to disk in the YAML format.

Examples

Example code can be found in the "js" tab of the dict help patcher.

See Also

Name Description
JavaScript Usage JavaScript Usage