Js method to add element to array