changing js code to reference from array