Sort an object by key or value.