You can us the (move:) macro to achieve the result you want.
(set: $inventory to (dm:
"first key", "first value",
"second key", "second value",
"third key", "third value"
))
Inventory before: (print: $inventory)
(set: $key to "second key")
(move: $inventory's ($key) into _buffer)
Inventory after: (print: $inventory)
NOTES:
1. You will need a variable to use as an 'into' target of move, I suggests using a temporary variable for that purpose unless you actually want to store/use that value.
2. Based on the documentation the correct way you use a value stored within a variable as the 'key' of an Array or a Datamap reference is to wrap that variable reference (an expression) within parenthesises like so:
(set: $key to "second key")
BAD reference to ''second key'' within datamap:
(print: $inventory's $key)
GOOD reference to ''second key'' within datamap:
(print: $inventory's ($key))
3. I also thought that a method similar to that you used in your original example would work, and I was equally surprised that it didn't.