S
S
S0mnium2013-08-19 16:44:47
JavaScript
S0mnium, 2013-08-19 16:44:47

Solution problem, bug or feature?

The bottom line is this - I write in the console:
var trade = [ [2, 9, 6, 3, 4, 5], [9, 2, 3, 4, 5], [9, 2, 3, 4, 5, 8], [9, 2, 3, 4, 5, 7] ]; var el=document.getElementById('trade');var gy = trade[parseInt(el.value)];for (var key in gy) { key; };
There is a selection from the array, and in response:
0 1 2 3 4 5 $family $constructor pop push reverse shift sort splice unshift concat join slice indexOf lastIndexOf filter forEach every map some reduce reduceRight each clone clean invoke associate link contains append getLast getRandom include combine erase empty flatten pick hexToRgb rgbToHex extend undefined

Where the rest of the trash comes from is not clear. I check in Chrome Version 28.0.1500.95

Answer the question

In order to leave comments, you need to log in

5 answer(s)
1
1x1, 2013-08-19
@S0mnium

hasOwnProperty?

D
d4rkr00t, 2013-08-19
@d4rkr00t

Because for in goes through all the properties of the object and its parents. Apparently, something extends the Object from which Array is inherited and adds just your garbage, hasOwnProperty is used to solve this problem. In your case, something like this:

if (gy.hasOwnProperty(key)) {
    console.log(key);
}

D
DeVitoz, 2013-08-21
@DeVitoz

In general, for in for arrays is not very recommended, perhaps it's better to just rewrite it with a regular loop, something like this:
for (var i = 0, max = gy.length; i < max; i++) {
console.log(gy[i]);
}

The most correct answer

N
noonesshadow, 2013-08-19
@noonesshadow

The console is open on a page with jQuery, or some plugin adds it.

V
vaail, 2013-08-19
@vaail

del

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question