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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:33:20+00:00 2026-06-01T18:33:20+00:00

I was trying to define an array (including other arrays as values) in a

  • 0

I was trying to define an array (including other arrays as values) in a single javascript statement, that I can loop through to validate a form on submission.

The function I wrote to (try to) create inline arrays follows:

function arr(){
    var inc;
    var tempa = new Array(Math.round(arguments.length/2));
    for(inc=0; inc<arguments.length; inc=inc+2) {
        tempa[arguments[inc]]=arguments[inc+1];
    }
    return tempa;
}

This is called three times here to assign an array:

window.validArr = arr(
    'f-county',arr('maxlen',10, 'minlen',1),
    'f-postcode',arr('maxlen',8, 'minlen',6)
);

However in the javascript debugger the variable is empty, and the arr() function is not returning anything. Does anyone know why my expectations on what this code should do are incorrect?

(I have worked out how to create the array without this function, but I’m curious why this code doesn’t work (I thought I understood javascript better than this).)

  • 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-01T18:33:21+00:00Added an answer on June 1, 2026 at 6:33 pm

    Well from what your code does, you’re not really making arrays. In JavaScript, the thing that makes arrays special is the management of the numerically indexed properties. Otherwise they’re just objects, so they can have other properties too, but if you’re not using arrays as arrays you might as well just use objects:

    function arr(){
        var inc;
        var tempa = {};
        for(inc=0; inc<arguments.length; inc=inc+2) {
            tempa[arguments[inc]]=arguments[inc+1];
        }
        return tempa;
    }
    

    What you’re seeing from the debugger is the result of it attempting to show you your array as a real array should be shown: that is, its numerically indexed properties. If you call your “arr()” function as is and then look at (from your example) the “f-county” property of the result, you’ll see something there.

    Also, if you do find yourself wanting a real array, there’s absolutely no point in initializing them to a particular size. Just create a new array with []:

        var tempa = [];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to define an array of file paths that I can loop
Im trying to define an array of arrays as a Constant in one of
I'm trying to understand what a JavaScript array is because traditional programming languages define
What I'm Trying To Do Basically, I've got several possible arrays that I define
I am trying to define an array with single element... so, var arr:Array =
I am trying to define a dynamic array containing char pointers that point to
I have been trying to assign value to an object array that is defined
I'm trying to define a delegate function that will return an IEnumerable. I'm having
I'm trying to define variables within a loop. I'll drop the code here and
I'm trying to use an array of arrays in a Perl object and am

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.