Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Idegoido · Aug 18, 2014 at 08:47 PM · javascriptarray

How do I make an array of arrays in javascript

I'm just learning and I wanted to do something simple so I figured making an array grid in javascript would be easy enough. However, no matter what I do I keep getting the error ArguementOutOfRangeException. Any advice of information on what I did wrong would be greatly appreciated.

P.S I'm sure that there's a more efficient way of doing this, like with lists or something, but I'm trying to practice with arrays.

 #pragma strict
 
     public var iMax = 10;
     public var jMax = 10;
     public var f : [];
     public var i: int;
     public var j : int;
 
     function  Start () 
     {
     for (i=0;i < iMax;i++) 
     {
          f[i]= [];
          for (j=0; j < jMax; j++) 
          {
               Debug.Log (f[i][j]);
          }
     }
     }
 I have this script attached to a random object, I figured it would work on anything but maybe I'm wrong.  
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Idegoido · Aug 18, 2014 at 08:04 PM 0
Share

thanks, but I'm more curious about what I did wrong. A friend of $$anonymous$$e said my code should work in theory. Thanks for the link though.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Yinoguns · Aug 18, 2014 at 09:52 PM

While i'm not all that Familiar with JavaScript (I prefer C# myself) I'm not sure about your code in general.

Such as why you would need an Array, of arrays, why not just a multidimensional array.

I found this link that shows literal declaration of an array, but is somewhat different to your code. ( var arlene = [ ]; ) http://freewebdesigntutorials.com/javaScriptTutorials/jsArrayObject/declareAnArray.htm

If I were to work off your code, I would hazard the guess that you are creating object f of type array so:

public var f : [ ]

Then, for X times (10) you make each part of F into an Array.

f[ [ ] ] or f[i] = [ ]

In which case I would say the whole thing then should work, other than theres no data other than empty arrays so im not sure how Unity would feel about that.

How about you make an Array Var, which contains Arrays of ints, perhaps then something might print?

Just some ideas and thoughts.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Reading and Storing External Data into Memory (From Text) 1 Answer

Type 'Object' does not support slicing. 1 Answer

Javascript - Calling a random String 2 Answers

Index out of bounds even tho it shouldnt be [Javascript] 1 Answer

Need help with OnTriggerEnter 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges