This line and the nearly identical one a few lines above it should be extracted into a function that takes an object and a key as parameters.