How to ? Do this?

How to ? Do this?

Im trying to substitute some hard coded code with an $each iteration.

From:
map.addOptimizedRoute([ {latLng: {lat:40.735383, lng:-73.984655}}, {latLng: {lat:40.763628, lng:-73.971524}}, {latLng: {lat:40.765058, lng:-73.989034}}, {latLng: {lat:40.750755, lng:-73.981824}} ]); 

To:
map.addOtimizedRoute([
$.each($locations ,function(idx) { 
$locations[idx],                   
})                                 
Or something akin to. I dont know how many points Im going to have to have to build an array.

 But dont have a clue about how to do this ... Yea