Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Javascript
<FAQENTRY> Array and hash (associative array)
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="VK, post: 4893552"] OK JavaScript array is not really an array. arrayObject.length keeps the highest index you managed to use so far. It has *no* connection with the actual array's length, it's just called so for further convenience. Array contains as many elements as you initialized *yourselve*. If you vant to know the real array length, you have to treat array as hash table (map, collection) and iterate through its key/value pairs. As the latter is the only way to treat JavaScript's array properly, it doesn't really matter what your're doing: adding key/value pair to the hash or adding indexed alement to the array. You're dealing with the same object anyway. push(), pop(), and other array methods are not needed in JavaScript. I agree on everything stated above. Just one humble ask: please do not put *this* to FAQ's. Eppur si mouve! Could we at least to mention in the FAQ's, that despite array and associative array (map, collection, hash table) is the same thing in JavaScript, its engine has some strange behavior: if you do arrayObject[SomeNumber] = someValue, it counts it in arrayObject.length It also lets you to use standard array methods on this member. (1st category) if you do arrayObject[SomeString] = someValue, the engine doesn't it in arrayObject.length and you cannot use standard array methods on this member. (2nd category) Until JavaScript/JScript engine producer will rectify this obvious bug, you need to be very attentive while putting new members in your arrayObject. As soon as array index is not an integer, new members falls into the 2nd category with all above listed consequences. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Javascript
<FAQENTRY> Array and hash (associative array)
Top