I generate this js at the server side so the arrays could have more elements
var o = 'hi world';
var keys = ['foo','bar'];
var values = ['foox', 'barzs'];
how can I optimize this part?:
var data = [{name:'prop', value: o}];
data.push({name: 'keys', value: 'foo'});
data.push({name: 'keys', value: 'bar'});
data.push({name: 'values', value: 'foox'});
data.push({name: 'values', value: 'barzs'});
$.post('url', $.param(data), ...);
I don’t know if with a limited example you’re really optimizing anything, but if you actually have large data sets, you could push the values via a loop…
again it depends on what you mean by optimize, but I’m assuming you are dealing with much larger data sets than your example, meaning having to write push statements every single value.