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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:33:08+00:00 2026-06-03T21:33:08+00:00

I try to create a dynamic 2 dimensional array using the prototype.slice.call. The array

  • 0

I try to create a dynamic 2 dimensional array using the prototype.slice.call. The array dimension varies depending on the value k inserted by the user. The code is as follows:

var A = new Array(k);

                if (k > 1) {
                    var args = Array.prototype.slice.call(k, 1);
                    for (var n = 0; n < k; n++) {
                        A[n] = new Array.apply(this, args);
                    }
                }



                alert (A);  
  • 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-03T21:33:09+00:00Added an answer on June 3, 2026 at 9:33 pm

    .slice() is the wrong tool. It’s used for making a shallow clone of another Array, or part of the Array.

    If you’re looking for a square structure, you’d just use 2 nested loops to create the outer and inner arrays.

    var k = 10;
    
    var a = [];
    for (var i = 0; i < k; i++) {
        a[i] = [];
        for (var j = 0; j < k; j++) {
            a[i][j] = i + ':' + j;
        }
    }
    

    http://jsfiddle.net/zGhnv/

    >[["0:0","0:1","0:2","0:3","0:4","0:5","0:6","0:7","0:8","0:9"],
    ["1:0","1:1","1:2","1:3","1:4","1:5","1:6","1:7","1:8","1:9"],
    ["2:0","2:1","2:2","2:3","2:4","2:5","2:6","2:7","2:8","2:9"],
    ["3:0","3:1","3:2","3:3","3:4","3:5","3:6","3:7","3:8","3:9"],
    ["4:0","4:1","4:2","4:3","4:4","4:5","4:6","4:7","4:8","4:9"],
    ["5:0","5:1","5:2","5:3","5:4","5:5","5:6","5:7","5:8","5:9"],
    ["6:0","6:1","6:2","6:3","6:4","6:5","6:6","6:7","6:8","6:9"],
    ["7:0","7:1","7:2","7:3","7:4","7:5","7:6","7:7","7:8","7:9"],
    ["8:0","8:1","8:2","8:3","8:4","8:5","8:6","8:7","8:8","8:9"],
    ["9:0","9:1","9:2","9:3","9:4","9:5","9:6","9:7","9:8","9:9"]]
    

    Notice that I really don’t need to declare the initial length of the Array. I can just add members to each array as needed.

    If you want to declare the length up front, you could replace both [] with new Array(k).

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

Sidebar

Related Questions

I try to create a very simple app using windows API. I've done some
I am trying to create dynamic excel sheet, with the help of php using
I am trying to create a dynamic UI using UpdatePanel of AJAX toolkit. Let
I'm using MVC3 and I wanted to use a partial view to create dynamic
i want to create a dynamic generated form using javascript, everything works fine, until
Using Rails 2, I try to separate different, dynamic image sizes trough another Model
I want to try create something like Zend's Server Pagecache. What I want to
I try to create a progress bar that displays the progress of a parser
I try to create Twitter client and now I deal with authorization via OAuth
I try to create an Application on Windows 8 with VS 11 with C#,

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.