javascript - Find length of an array in jquery getting wrong result -
i have javascript code below size of array,
var testvar = [ ]; testvar[1] = 2; testvar[200] = 3; alert(testvar.length); //201
but code alerts 201
insted of getting size 2
,why?
i need count of total elements in array.
if want find length of array despite doing such things :
alert(object.keys(testvar).length);
https://jsfiddle.net/4lqsf45a/
note object.keys()
not avaiable in ie < 9. see https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/object/keys workarounds
Comments
Post a Comment