javascript - Why on earth is jack showing up in the sequence of alert boxes? -


object.prototype.jack = {};  var = [1,2,3];  for(var number in a){     alert(number); } 

could tell me why word "jack" jumped out of alert box?

thank much!

simple - arrays objects in javascript adding:

object.prototype.jack={}; 

you've added enumerable property 'jack' objects (and arrays).

once creating array "a" , looping through of properties

for(var number in a) 

you sure 'jack' alert. avoid showing can use .hasownproperty() make sure alerted properties not inherited. or use regular

for(var i=0; < a.length; i++) 

loop.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -