All Questions

1428
votes
24answers
640351 views

Why is using "for...in" with array iteration a bad idea?

I've been told not to use for...in with arrays in JavaScript. Why not?
2182
votes
34answers
2511776 views

Loop through an array in JavaScript

In Java you can use a for loop to traverse objects in an array as follows: String[] myStringArray = {"Hello", "World"}; for (String s : myStringArray) { // Do something } Can you do the same in...
174
votes
7answers
71957 views

Elements order in a "for (… in …)" loop

Does the "for…in" loop in Javascript loop through the hashtables/elements in the order they are declared? Is there a browser which doesn't do it in order? The object I wish to use will be declared o...
594
votes
17answers
614999 views

What is the difference between ++i and i++?

In C, what is the difference between using ++i and i++, and which should be used in the incrementation block of a for loop?
57
votes
5answers
36345 views

Asynchronous Process inside a javascript for loop

I am running an event loop of the following form: var i; var j = 10; for (i = 0; i < j; i++) { asycronouseProcess(callBackFunction() { alert(i); }); } What I would like this to ...
243
votes
14answers
71101 views

Why does python use 'else' after for and while loops?

I understand how this construct works: for i in range(10): print(i) if i == 9: print("Too big - I'm giving up!") break; else: print("Completed successfully") But I don'...
148
votes
17answers
507181 views

Get Radio Button Value with Javascript

I'm having some strange problem with my JS program. I had this working properly but for some reason it's no longer working. I just want to find the value of the radio button (which one is selected) an...
255
votes
39answers
138059 views

In .NET, which loop runs faster, 'for' or 'foreach'?

In C#/VB.NET/.NET, which loop runs faster, for or foreach? Ever since I read that a for loop works faster than a foreach loop a long time ago I assumed it stood true for all collections, generic coll...
13
votes
3answers
7107 views

Why is my function call that should be scheduled by setTimeout executed immediately?

Here's my issue. I have this function to test proxy servers. function crawl() { var oldstatus = document.getElementById('status').innerHTML; document.getElementById('status').innerHTML = olds...
284
votes
7answers
34100 views

Why does the order of the loops affect performance when iterating over a 2D array?

Possible Duplicate: Which of these two for loops is more efficient in terms of time and cache performance Below are two programs that are almost identical except that I switched the i and j...

Previous Next