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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:07:13+00:00 2026-06-04T07:07:13+00:00

This is based on my last question. I have these arrays: var array1 =

  • 0

This is based on my last question.

I have these arrays:

var array1 = new Array ("Pepsi", "Coke", "Juice", "Water");
var array2 = new Array ("35",    "17",   "21",    "99");

And I want to combine them to form a multidimensional array like this:

[
    ["Pepsi","35"]
    ["Coke", "17"]
    ["Juice","21"]
    ["Water","99"]
]

I tried this script:

Values=[];

for (i = 0; i < array1.length; i++) {
    Values[i] = Array(array1[i], array2[i]);
}

But it gave a result like this (correct values, incorrect names):

[
    ["a","35"]
    ["c","17"]
    ["E","21"]
    ["I","99"]
]
  • 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-04T07:07:14+00:00Added an answer on June 4, 2026 at 7:07 am
    var array1 = ["Pepsi", "Coke", "Juice", "Water"],
        array2 = ["35", "17", "21", "99"],
        result = [], i = -1;
    
    while ( array1[++i] ) { 
      result.push( [ array1[i], array2[i] ] );
    }
    

    As written, this solution assumes you will only ever be using strings. As @ajax333221 has pointed out in the comments below, this would cause problems if you were to involve boolean or int values into this solution. As such, I’d like to propose an improvement that will accomplish your goals, while not tripping over difficult values and types:

    var array1 = [false, 0, "Juice", -1],
        array2 = ["35", "17", "21", "99"],
        result = [];
    
    for ( var i = 0; i < array1.length; i++ ) {
      result.push( [ array1[i], array2[i] ] );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is based on the thread . I have the shell function function
Based on my last question , I have tried to separate the business logic
Based on this question Group files and pipe to awk command I have a
This is based on a similar question How to Replace Multiple Characters in Access
This is based on my full question . I decided to take it in
I am designing a simple web-based application. I am new to this web-based domain.I
This question is based on this thread . Is [---] a comment in Git
This question is based on this thread . I am interested in how Git
This question is based on this thread . The code function man() { man
Easy question, it is valid to have overlapping spans in html? Example: <span id=1>This

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.