- Home /
Javascript array questions.
In unity javascript you can create string arrays in single line of code:
var myStrArr = ["a","b","c"];
So you don't need to set any size for the string array.
However, I didn't find a way to set int or float array in single line of code.
var myIntArr = new int[3]; // Set size of the array
myIntArr = [1,2,3]; // Set int 1,2,3 to first three
// indexes (0,1,2)
So is there a way to make int or float array on a single line of code where you set its size and all integers or floats that it contains?
Second question, how can I use array of arrays or 2D matrix arrays?
Answer by robertbu · Jul 30, 2014 at 05:06 AM
This question has an old date, but jumped to the top of the Queue today. Not sure if your clock is off, or if you edited one of your old questions. For declaring and initializing an array of ints in Javascript/Unityscript, you can do:
var someInts : int[] = [ 0,1,2,3,4,5 ];
There are a number of answers on UA concerning multi-dimensional arrays. The answer will depend on whether you are looking for a 2D (or 3D) array, or if you are looking for a Jagged array. Google 'Jagged Array' if you don't know the difference. Here is one answer on multi-dimensional arrays.
http://answers.unity3d.com/questions/54695/how-to-declare-and-initialize-multidimensional-arr.html
Your answer
Follow this Question
Related Questions
Having Multiple Controllable FPS Units Selected From A Singular RTS Mode? 0 Answers
Bigger matrix? 3 Answers
Error with an Array 1 Answer