I have a select list (sample below). I want to store this select list (text and value) in a JSON object or Array object. So that i can later go thru it using .each function. I want to then show/hide the records in the select option list based on user input. all code is ready and working except that I am not able to figure how to store a select option list with all its text and value pairs into an either Array or JSON object and subsequently able to walk thru it based on text.
thank you.
<select id="mySelect" multiple="multiple">
<option value="1">First</option>
<option value="2">Second</option>
<option value="3">Third</option>
<option value="4">Fourth</option>
</select>
My answer is very similar to @topek's but I'm using object to store array elements so it may be useful. You can inspect working example here.
HTML:
Javascript:
You can try this fiddle:
HTML
JAVASCRIPT
Console Log Output: