I'm looking for something similar to the $set
operator in Mongo and wasn't able to find it in the JS documentation:
http://docs.mongodb.org/manual/reference/operator/update/set/
I want to replace the value of a field to another specified value. If the field does not exist, I want to add the field with the specified value. BUT if there are existing fields in the object already I don't want to overwrite them.
Say that I've got this:
var hashTable = { key1: "Original Stuff", key2: "More Stuff" }
I want to update key2
to something else, but only key2
. I want to leave key1
alone. Additonally, I want to add in a key3
. It would be nice if there some something like:
var hashTable = hashTable.set( {key2: "Edited Stuff", key3: "Added stuff"} )
hashTable would then be
{ key1: "Original Stuff", key2: "Edited Stuff", key3: "Added Stuff" }
EDIT
Imagine that the original object and the object I want to use as an updating parameter both have tons and tons of fields. I'm not going to be doing hashTable.key2 = "Edited Stuff"