Slice utility for objects and arrays