It's not an array, it's a regular object.
quote:
Originally posted by matty
jscript code:
// Declare an object to hold our ChatWindows
var oChatWnds = {};
Basically, you're not defining an element in a zero-based numerical indexed array, you're setting an object property of a regular object. If you were going to use:
jscript code:
var oChatWnds = [];
and then set and delete the 1053th element, yes, then you'd be wasting memory and processing time. But here, we only define one object property which simply happens to have a numeric property name - no problems at all.
JavaScript is very lax at such kind of stuff, unlike C++ where you can't make arrays with mixed element types. Compare JavaScript's object creation (like in this example) with extending an empty class: you start with nothing and add stuff in it. You won't create more properties in the class than you want (compared to JavaScript arrays), there's no length property or not-enumerable methods like push and slice. You simply extend an empty object.
quote:
Originally posted by MrPickle
Would this be acceptable.
...
This would mean you wouldn't have massive gaps but you'd have to loop through the chats.
Correct, but it's much faster and efficient to have them indexed by handle in an object than looping through an array and checking the Handle property. Also, in your example code, there's no way to get access to the ChatWnd object itself through the array, however it could be you simply forgot that.