Forum Discussion
Hi Yuri,
You can use the Array.push method to add elements to an aray dynamically:
var arr = []; // empty array for (var i = 0; i < 5; i++) arr.push(i); Log.Message(arr.length); // 5
- Colin_McCrae9 years agoCommunity Hero
^^^
Except that the (hard coded) loop length defines the array size in the above example.
So doing it dynamically is pointless. As you already know in advance it will be 5.
(Handy to know nonetheless as I assume it will be the same in C# Script .... which is what I'm currently using/learning as I go)
Much like the OP where the RowCount can be retrieved and known before the array is declared so dynamic declaration should not be required?
- HKosova9 years agoSmartBear Alumni (Retired)
It was just an example to illustrate the idea of dynamic array initialization. JavaScript/JScript arrays are dynamic by design, you can add and remove array elements at any time.
var arr = []; while (condition) { arr.push(element) } arr.pop(); // remove last element arr.splice(3, 1); // remove 1 element at index 3
Reference: JScript Array object
- Colin_McCrae9 years agoCommunity Hero
Yeah. I know.
But it did illustrate beautifully that you don't need to do it dynamically if you know the required size in advance ... :smileylol:
Related Content
- 6 years ago
Recent Discussions
- 5 days ago
- 5 days ago