adding replace element in an array and use slice method