When working in PHP, performing the following code:
$var = array();
$var[5000] = 1;
echo count($var);
Will result in the output of 1.
However, in JavaScript, missing elements are created.
<script type="text/javascript">
var fred = [];
fred[10] = 1;
alert(fred.length);
</script>
This code will alert "11".
Is there a way to prevent this behavior in JavaScript? And is it beneficial in any way? As a PHP developer transitioning to JavaScript, I am seeking answers.
UPDATE:
I am currently working on an application utilizing Google Maps v2 and markerManager. Although the code has been functioning correctly for some time, an issue has recently emerged in Chrome (version 17.0.963.56) where markers appear duplicated and the rendering of moved markers behaves erratically, sometimes leading to browser freezes. Upon inspecting the DOM using Firebug, I noticed numerous "undefined" elements in arrays under the grid_ variable in markerManager. I am thinking that by removing these elements, I may be able to streamline the code, even if it doesn't directly address the marker problem. Appreciate any insights or advice. Thank you.