In jQuery if you have select multiple with two values if I use:
$('select').val()
I've got:
["foo", "bar"]
but in javascript/native DOM:
$('select')[0].value
I've got:
"foo"
why I've got just the first value and not an array? How to get the same value as in jQuery? I don't see anything special in jQuery source code that check if select have attribute multiple.
Here is demo:
console.log($('select').val());
console.log($('select')[0].value);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select multiple>
<option value="foo" selected>foo</option>
<option value="bar" selected>bar</option>
</select>