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

  • SEARCH
  • Home
  • 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 8850103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:49:19+00:00 2026-06-14T12:49:19+00:00

I need options’ value list in an array or JSON. I have used following

  • 0

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.

  • 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-06-14T12:49:21+00:00Added an answer on June 14, 2026 at 12:49 pm

    You can use custom serializer like this:

    var options = Array.prototype.slice.call(document.getElementById("sel").options),
        str = JSON.stringify(options, function(key, value){
           if(key === ""){
               return value;   
           }
           if(!isNaN(parseInt(key))) {
              return value.value;   
           }
        };
    

    http://jsfiddle.net/Vh9qD/

    Or use iteration without creating jQuery instance for every option

    var options = Array.prototype.slice.call(document.getElementById("sel").options),
        str = JSON.stringify(options.map(function(item){return item.value;}));
    

    Check this perf test: http://jsperf.com/get-options

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a drop down list that has options that need to be passed
Need to take a SELECT drop down list options and find if any of
I need to know how to retrieve each product's custom options (name/value) in an
I need your advice on this piece of code: the table fields options[0], options[1]
I need some options. I have a table layed out as follows with about
I need to populate a dropdown list when I select a certain value and
Need the three Options to be hyperlinks that submit the choice form. When submitted,
Need to call a filter function on some options based on a radio selected
I need to set/unset configure options for an in-house C# software through its GUI.
I need to set up some SET options in Oracle SQLplus command line program

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.