Select to view content in your preferred language

Arcade - add new values to Dictionary

3149
2
Jump to solution
08-11-2022 06:50 AM
girafee
Emerging Contributor

Hi! I want to add new values to the dictionary and haven't found a method that can help me.

var first = Dictionary('field1', 1, 'field2', 2)

If I want to add new key/value in the Dictionary, what can I use? 

1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

By assigning a value to a key, Arcade will overwrite an existing value or create a new key if it doesn't already exist.

var f = Dictionary('field1', 1, 'field2', 2)

// add new key/value pair
f['field3'] = 'hey'

// overwrite existing value
f['field1'] = 'overwrite!'

return f

jcarlson_0-1660226026057.png

PS - I'm assuming that's just a made-up sample, but don't use existing function names like first as variable names, it's just asking for trouble!

- Josh Carlson
Kendall County GIS

View solution in original post

2 Replies
jcarlson
MVP Esteemed Contributor

By assigning a value to a key, Arcade will overwrite an existing value or create a new key if it doesn't already exist.

var f = Dictionary('field1', 1, 'field2', 2)

// add new key/value pair
f['field3'] = 'hey'

// overwrite existing value
f['field1'] = 'overwrite!'

return f

jcarlson_0-1660226026057.png

PS - I'm assuming that's just a made-up sample, but don't use existing function names like first as variable names, it's just asking for trouble!

- Josh Carlson
Kendall County GIS
girafee
Emerging Contributor

Thank you Josh Carlson! This is the example I was looking for.