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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:35:12+00:00 2026-05-18T01:35:12+00:00

Can someone assist me with formatting this JavaScript array correctly? I am obviously missing

  • 0

Can someone assist me with formatting this JavaScript array correctly? I am obviously missing something fundamental:

Javascript:

<script type="text/javascript">

    var widths = new Array("225","320","480", "--");
    var sidewalls = new Array();
    sidewalls["225"] = new Array("65","55","45","40", "--");
        var rims["225"] = new Array();
            rims["225"]["65"] = new Array("R17", "--");
            rims["225"]["55"] = new Array("R17","R18", "--");
            rims["225"]["45"] = new Array("R17", "--");
            rims["225"]["40"] = new Array("R18", "--");
    sidewalls["320"] = new Array("70", "--");
        var rims["320"] = new Array();
            rims["320"]["70"] = new Array("R20","R24", "--");
    sidewalls["480"] = new Array("65", "--");
        var rims["480"] = new Array();
            rims["480"]["65"] = new Array("R28", "--");

</script>

PHP used to generate the above JavaScript:

<?php   while($row = mysql_fetch_array($result)) {
    list($width, $sidewall, $rim) = explode("/",$row['meta_value']); $menu[$width][$sidewall][$rim] = 1; } 

    $widths = implode('","', array_keys($menu));
        print "var widths = new Array(\"$widths\", \"--\");\n";
        print "\nvar sidewalls = new Array();\n";

    foreach($menu as $width => $sidewall_array) {
        $sidewalls = implode('","', array_keys($sidewall_array));
            print "sidewalls[\"$width\"] = new Array(\"$sidewalls\", \"--\");";
            print "\nvar rims[\"$width\"] = new Array();\n";

    foreach($sidewall_array as $sidewall => $rim_array) {
        $rims = implode('","', array_keys($rim_array));
            print "rims[\"$width\"][\"$sidewall\"] = new Array(\"$rims\", \"--\");";

    }
} ?>

Thank you in advance for your help

Stu

  • 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-18T01:35:13+00:00Added an answer on May 18, 2026 at 1:35 am

    You shouldn’t be putting var in front of array assignments, just the initial definitions.

    So var widths = ... is fine, but var rims["225"] = ... is incorrect and should just be rims["225"] = ....

    Change your php; in the line of code that outputs that text remove the “var”. Change this:

    print "\nvar rims[\"$width\"] = new Array();\n";
    

    To this:

    print "\nrims[\"$width\"] = new Array();\n";
    

    That will solve your problem. But really, this overall solution is not the best. You ought to consider looking into the json-encode php method.

    You can take a fully-structured php data structure and with this one command convert to something that can be read by javascript. Try replacing your php with the below and see what happens (note that this is untested, but this is the basic idea):

    <?php
        while($row = mysql_fetch_array($result)) { list($width, $sidewall, $rim) = explode("/",$row['meta_value']); $menu[$width][$sidewall][$rim] = 1; }
    
        print "var widths = " . json_encode(array_keys($menu)) . ";\n";
        print "var sidewalls = " . json_encode($menu) . ";\n";
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone explain this result to me. The first test succeeds but the second
Just wondering if someone can assist me with the following issue. I have a
Just wondering if someone can assist me with the following issue. I have come
can someone assist me with fixing the error i'm receiving. $search_key = ''; /*if(isset($_POST)
Can someone show me how to implement a recursive lambda expression to traverse a
Can someone explain the mechanics of a jump table and why is would be
Can someone give an example of a good time to actually use unsafe and
Can someone describe what a symbol table is within the context of C and
Can someone explain to me the advantages of using an IOC container over simply
Can someone explain what exactly the string 0 but true means in Perl? As

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.