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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:41:15+00:00 2026-06-11T05:41:15+00:00

I have a multidimensional array (retdata[R][C]) that basically looks like a spreadsheet of cells.

  • 0

I have a multidimensional array (retdata[R][C]) that basically looks like a spreadsheet of cells. R represents the rows, C the columns. I want to create an array of objects so that I get the following

 [{retdata[1][1]:retdata[2][1],retdata[1][2]:retdata[2][2],retdata[1][3]:retdata[2][3]    }, 
  {retdata[1][1]:retdata[3][1],retdata[1][2]:retdata[3][2],retdata[1][3]:retdata[3][3]    },
  {retdata[1][1]:retdata[4][1],retdata[1][2]:retdata[4][2],retdata[1][3]:retdata[4][3]    }, 
 etc...
]

The resulting array should be:

 [{"Col1":"dataR2C1","Col2":"dataR2C2", "Col3":"dataR2C3"}, 
 {"Col1":"dataR3C1","Col2":"dataR3C2", "Col3":"dataR3C3"}, 
 {"Col1":"dataR4C1","Col2":"dataR4C2", "Col3":"dataR4C3"}, 
 etc...
]

I have tried a number of options without success. Any help would be greatly appreciated.

Here is one example I have used but it id not serializing the objects properly.

                var TABLE = [];
                for (var i=2; i<=rows; i++) {
                    var ROW = {};                       
                    for (var j=1; j<=columns; j++){
                        name = retdata[1][j].toString;
                        value = retdata[i][j].toString;
                        ROW += {name: value}
                    }

                TABLE += ROW;   

                }
  • 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-11T05:41:16+00:00Added an answer on June 11, 2026 at 5:41 am

    This is like a CSV-parser, the first row of your table are the keys for the line-objects. Your function would work, but you need to correct your array indices: they always start at 0, running up to n-1. Also, you need to learn a bit JavaScript syntax:

    • something.toString does not call the toString function on that value, but gets that function (it’s just an object).
    • You don’t need toString at all – where needed, values are automatically casted
    • You can’t add key-value-pairs to object with a simple operator. You will need to assign the value to that property of an object, with the bracket notation. The += operator would have casted the values to strings and concatenated them.
    • It’s the same with arrays. You could use the .push() method, or just assign to a numerical key – the javascript array object will automatically update its length.
    var retdata = […];
    
    var table = [],
        keys = retdata.shift(); // get & remove the first row
    for (var i=0; i<retdata.length; i++) {
        var row = {};
        for (var j=0; j<retdata[i].length; j++)
            row[ keys[j] ] = retdata[i][j];
        table[i] = row;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an multidimensional array that looks like this: Array ( [0] => Array
I have a multidimensional array that looks something like this: ourThing = array( 'id'
I have a multidimensional array that looks like this: Array ( [0] => Array
I have a multidimensional array that looks like this [0] => Array ( [recordId]
I have a multidimensional array that looks like this: Array ( [0] => Array
I have a multidimensional array in PHP, something that looks like: array(array(Category => Video,
I have a multidimensional array that look like this: Array [1] => Array (
I have a multidimensional-array which looks like this: $array = ( [0] => array
I have a multidimensional array and I want to have the output that only
I have a multidimensional associative array, and I want to apply array_walk_recursive so that

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.