Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5940865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:01:43+00:00 2026-05-22T16:01:43+00:00

From what I understand a option elements that popuate select elements in HTML are

  • 0

From what I understand a option elements that popuate select elements in HTML are an array.
So basically what i want to do is return an array string that is separated by commas.

Tried to do selecbox.options.join(',');, but got an error that its not supported; anyone have an idea why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:01:44+00:00Added an answer on May 22, 2026 at 4:01 pm

    It is not an array. It is an HTMLCollection. It is "array-like"

    In 2022, a week before EOL of Internet Explorer 11, the simplest vanilla JavaScript solution is using spread and Array map

    UPDATE: Array.from is actually preferable to the spread since it is more obvious what is going on

    const opts = document.querySelectorAll("select option"); 
    // we can use forEach on the resulting HTMLCollection 
    // but map needs to be spread to array
    const vals = Array.from(opts) // or [...opts]
      .map(el => el.value); 
    console.log(vals);
    <select>
    <option value="Please select">Text 0</option>
    <option value="one">Text 1</option>
    <option value="two">Text 2</option>
    <option value="three">Text 3</option>
    </select><br/> 
    The above select has the following option values:<br/>
    <span id="result"></span>

    Older answer that is compatible with IE11

    from http://api.jquery.com/jQuery.each/ which CAN iterate over either:

    Iterate over both objects and arrays.
    Arrays and array-like objects with a
    length property (such as a function’s
    arguments object) are iterated by
    numeric index, from 0 to length-1.
    Other objects are iterated via their
    named properties.

    Each HTML Option element has a value and a text and some more attributes.

    A simple for loop can be used

    vals = []
    var sel = document.querySelector("select");
    for (var i=0, n=sel.options.length;i<n;i++) { // looping over the options
      if (sel.options[i].value) vals.push(sel.options[i].value);
    }
    

    the Array.apply posted by typeracer will return an array of HTMLOptionElements which still needs to be looped over or mapped to get at the values and texts

    Here are a few versions that will return the same.

    This fiddle will run in IE11 too

    var vals, sel = document.querySelector("select"), show=function(vals) {$("#result").append("[" + vals.join("][") + "]<hr/>");}
    var supportsES6 = function() {try{new Function("(a = 0) => a");return true;}catch (err) {return false;  }}();
    
    
    // jQuery mapping jQuery objects - note the "this" and the .get()
    vals = $('select > option').map(function() {return this.value;}).get();
    show(vals);
    
    // plain JS using loop over select options
    vals = [];
    for (var i = 0, n = sel.options.length; i < n; i++) { // looping over the options
      if (sel.options[i].value) vals.push(sel.options[i].value); // a bit of testing never hurts
    }
    show(vals);
    
    // Plain JS using map of HTMLOptionElements - note the el
    vals = Array.apply(null, sel.options).map(function(el) { return el.value; });
    show(vals);
    
    // ES6 JS using spread and map of HTMLOptionElements - note the fat arrow and el
    if (supportsES6) 
      document.write(`<script>
    
      vals = [...sel.options].map(el => el.value);
    
    show(vals);
    <\/script>`
    );
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <select>
    <option value="Please select">Text 0</option>
    <option value="one">Text 1</option>
    <option value="two">Text 2</option>
    <option value="three">Text 3</option>
    </select><br/> 
    The above select has the following option values:<br/>
    <span id="result"></span>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How should I understand $(select option:selected) in the following code ? (taken from here
I'am trying to understand the example from program_options of the boost library ( http://www.boost.org/doc/libs/1_38_0/doc/html/program_options/tutorial.html#id3761458
I am using DBus in a project. I understand from DBus specification that for
I have a List[Option[Int]] and want to sum over it using applicative functors. From
Which is the best way to add <option>...</option> to a select that has been
I have a JSON string (from PHP's json_encode() that looks like this: [{id: 1,
From what I understand, the parent attribute of a db.Model (typically defined/passed in the
From what I understand, due to the same origin policy enforcement in current browsers,
From what I understand, in TDD you have to write a failing test first,
From what I understand of the SDK, this exception is raised when the bindings

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.