Answer the question
In order to leave comments, you need to log in
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
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);
}
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 console is open on a page with jQuery, or some plugin adds it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question