To get values by field name, use get().
data.get('color');
If there are multiple values sharing the same field name, use getAll().
data.getAll('colors');
To replace values by field name, use set().
data.set('color', '#abcdef');
It's important to note that set()
replaces while append()
appends when the field name exists. From the docs:
The set()
method of the FormData
interface sets a new value for an existing key inside a FormData
object, or adds the key/value if it does not already exist.
The difference between set()
and FormData.append
is that if the specified key does already exist, set()
will overwrite all existing values with the new one, whereas FormData.append
will append the new value onto the end of the existing set of values.
To delete values by field name, use delete().
data.delete('color');