...
The put()
operator takes two arguments: a hash path and a new element to be inserted. The element must itself be a map. The result is a new data a structure with the element inserted at the location specified by the hash path. If the path specifies a location that does not exist, it will be created. If the location already has a value, it will be replaced by the new element. For example:
Code Block | ||||
---|---|---|---|---|
| ||||
a = { "colors" : "many", "pi" : [3,1,4,1,5,6,9] }; b = {"flop" : 12}; c = a.put(["foo"], b); // c = { "colors" : "many", // "pi" : [3,1,4,1,5,6,9], // "foo" : {"flop" : 12} // }; d = a.put(["foo", "bar"], b); // d = { "colors" : "many", // "pi" : [3,1,4,1,5,6,9], // "foo" : {"bar" : {"flop" : 12}} // }; |
...