Linked Questions
20 questions linked to/from JavaScript Loops: for...in vs for
0
votes
1
answer
857
views
JavaScript: console.log() producing numbers instead of characters [duplicate]
Why do I get numbers (0 through 9) for trying to print each character in the string? The string's length is 10 so am I getting the index of each letter? How can I get the characters instead? I would ...
25
votes
4
answers
27k
views
Javascript for..in vs for loop performance
I was clustering around 40000 points using kmean algorithm. In the first version of the program I wrote the euclidean distance function like this
var euclideanDistance = function( p1, p2 ) { // p1....
7
votes
1
answer
44k
views
Uncaught TypeError: items is not iterable
My understanding is that for...in loops are designed to iterate over objects in Javascript. See this post and this post.
Take the following example. This returns 'Uncaught TypeError: items is not ...
1
vote
6
answers
16k
views
for(var i in aArray) VS for(i=0; i<aArray.length; i++)
I just want to ask if the in_array_orig and in_array_new is just the same.
and also im confused on the result when comparing both array (aArr1 vs aArr2).
can someone explain me. thanks
Here is my ...
4
votes
1
answer
5k
views
Iterating over an array with "holes" in JavaScript
I have got an array from which some items are going to be removed; but some loops are still running on them, so I want to simply skip the places where I remove my objects
I know that the syntax for(i ...
0
votes
4
answers
283
views
why does JS for each in function give too many?
This has bothered me for a while, see my jsfiddle: http://jsfiddle.net/DHR8Q/, which contains the following javascript code:
var id = "11111;22222;33333";
id = id.split(";");
alert(typeof id);
for ...
3
votes
3
answers
3k
views
Javascript: for(var i < array.length) v.s. for (e in array)
I think there must be a question like this before but current search engines cannot give you results to queries of code lines.
My question is:
What's the difference between
for ( var i = 0; i <...
3
votes
2
answers
3k
views
Select all checkboxes JS toggle issue
Hoping someone can help me overcome my Javascript ignorance.
I've got a form that includes checkboxes and I've got a piece of JS that toggles selecting/deselecting all the boxes. And so far, it all ...
0
votes
3
answers
2k
views
difference between for..in and for loops, and counter declaration
the difference (speed, performace, side effects, ...) between implementations of the for loop:
between
var i;
for(i = 0; i < length; i++){ //Do something}
// more code
and
for(var i = 0; i < ...
0
votes
3
answers
351
views
increment away from zero in an array in js
I have the following js script. It uses alert to count the days of the week day 0 Monday ... day 6 Saturday. i starts with 0 since this is js.
<script>
var days = ['Sun', 'Mon', 'Tues', 'Wed',...
1
vote
4
answers
301
views
For loop skipping over the rest of items in an array after two iterations
Apology:
I apologize if this is a really basic question, I've looked around but since I never did get a very solid grounding in Javascript objects, I may be looking for answers in all the wrong ...
1
vote
5
answers
237
views
Accessing sub-objects in a "for in" loop?
Here is some sample code of what I am trying to achieve:
pingpong = {
paddleA: {
speed: 5,
},
paddleB: {
speed: 6,
},
paddleAI: {
AI1: "paddleA",
...
2
votes
3
answers
111
views
Retrieving links from webpage using javascript
I'm new to javascript and simply trying to pull links from a webpage so I'm doing the following:
for(link in document.links) {
console.log(link.getAttribute("href");
}
But if I do this:
document....
0
votes
2
answers
316
views
javascript for...in + if-test (inside of a switch inside of a form)
I have a question in a form asking if you've used alcohol, drugs, both, neither, "777", "999".
alcohol : question 2; drugs : question 3; both : questions 2 + 3; neither or "777" or "999" : question ...
0
votes
0
answers
246
views
weird "addEventListener is not a function" exception [duplicate]
the code below cannot run properly on Google Chrome :
var e,
divStyle = {
backgroundColor: "rgba(153, 153, 153, 0.29)",
postion: "fixed",
top: 0,
left: 0,
...