If you're using jQuery:
var arr = $('#mySelect option').map(function(){
return this.value;
}).get();
JS Fiddle demo.
The reason that options[i].val() failed is that options[i] is a native DOM node, not a jQuery object.
If you'd like to do the same with plain JavaScript:
var opts = document.getElementById('mySelect').getElementsByTagName('option'),
arr = [];
for (var i = 0, len = opts.length; i < len; i++) {
arr.push(opts[i].value);
}
JS Fiddle demo.
Or, for more up-to-date browsers:
var opts = document.querySelectorAll('#mySelect option'),
arr = [];
for (var i = 0, len = opts.length; i < len; i++) {
arr.push(opts[i].value);
}
JS Fiddle demo.
And in slightly more modern browsers:
var arr = [].map.call(document.querySelectorAll('#mySelect option'), function(a){
return a.value;
});
console.log(arr);
JS Fiddle demo.
Also, if you'd like to take both the value and the text-content from the options (as a simple demo, using the second code-sample from above as the basis):
var opts = document.getElementById('mySelect').getElementsByTagName('option'),
arr = [], tmp;
for (var i = 0, len = opts.length; i < len; i++) {
tmp = opts[i];
arr.push({'value' : tmp.value, 'content' : (tmp.textContent || tmp.innerText)})
}
console.log(arr);
JS Fiddle demo.
References:
- 'Plain' JavaScript:
- jQuery:
$select.options[i].val()