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 8014583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:58:51+00:00 2026-06-04T19:58:51+00:00

I need JavaScript array/multidimensional which is returned by Java class, <script type=text/javascript> var strComboValue

  • 0

I need JavaScript array/multidimensional which is returned by Java class,

<script type="text/javascript">
     var strComboValue  = <%=DBComboOptions.getOptions(combos)%>;
</script>

Here, strComboValue is a JavaScript variable and the DBComboOptions.getOptions(combos) returns array in Java class. Now I want that array in JavaScript.

  • 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-04T19:58:52+00:00Added an answer on June 4, 2026 at 7:58 pm

    Just let Java/JSP print a syntactically valid JS array syntax. Keep in mind that Java/JSP and JavaScript doesn’t run in sync. Java/JSP produces HTML as one large String and JS is just part of it. JS ultimately runs in the webbrowser once it has retrieved all that HTML output from Java/JSP.

    Assuming that you ultimately want the following valid JS array syntax:

    <script type="text/javascript">
        var strComboValue = [ "one", "two", "three" ];
    </script>
    

    Then you should write your Java/JSP code accordingly so that it prints exactly that syntax:

    <script type="text/javascript">
        var strComboValue = [ 
    <% 
        String[] options = DBComboOptions.getOptions(combos);
        for (int i = 0; i < options.length; i++) {
    %>
            "<%= options[i] %>"
    <%
            if (i + 1 < options.length) {
    %>
                ,
    <%
            }
        }
    %>
        ];
    </script>
    

    It’s only terribly unreadable (and not only because of using old fashioned scriptlets instead of taglibs). Easier, however, is to grab a JSON (JavaScript Object Notation) library like Google Gson and create an additional method getOptionsAsJson() which does something like the following:

    public getOptionsAsJson(Object value) {
        return new Gson().toJson(getOptions(value));
    }
    

    And finally use it instead:

    <script type="text/javascript">
        var strComboValue = <%=DBComboOptions.getOptionsAsJson(combos)%>;
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 'multidimensional associative' javascript array (which in fact is object with properties as
I need to group element of a multidimensional array in javascript. This is my
in my app i need to send an javascript Array object to php script
I have a JavaScript array as below which I need to filter to get
I have an javascript array, which looks like: var styles = new Array(); styles[0]
I have an array in javascript that I need to join and send through
I need to return an array in php and use it in javascript. When
Working with regular javascript, I need to store info into an array for output
In javascript I need to get the text within the custom tag. For example
How would you sort a multidimensional array in JavaScript? I have an array full

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.