function someName(from, to){ var result = []; while(from++ < to){ result.push( ".number" + from ); }; return result.join(", "); }; alert( someName(2,4) );