avoid using array.slice