normalize a javascript array