I need options' value list in an array or JSON. I have used following code.
var compArray=[];
jQuery("#myCombo option").each(function(){
compArray.push(jQuery(this).val());
});
But i dont want to iterate the options in a loop because my options list can grow. I have used as
JSON.stringify(document.getElementById("myCombo").options)
But on stringify it shows empty JSON objects, though I can get value from
document.getElementById("myCombo").options[0].value
I have to pass these value in request parameter to server and I do not want to go through the looping. Please suggest the optimized solution.
select.options[i]isHTMLOptionElementwhich has references to its parent and such... Just do not create jQuery instance for each option.Array.prototype.slice.call(document.getElementById("myCombo").options).map(function (item) {return item.value;})