javascript array replace element if exists