Linked Questions
835 questions linked to/from Why is using "for...in" for array iteration a bad idea?
14
votes
4
answers
4k
views
Why is JavaScript's For...In loop not recommended for arrays? [duplicate]
I read somewhere (sorry, I can't find the link) that the For...In loop is not recommended for arrays. It is said here: http://www.openjs.com/articles/for_loop.php that it is meant for associative ...
17
votes
3
answers
12k
views
Difference between for(i in array) and for(var i=0;i<array.length;i++) [duplicate]
This would be a very easy question for all you javascript/jquery guys.
I've been programming javascript from past 2 years and today I faced a strange problem.
I am fetching a JSONarray from my C# ...
9
votes
1
answer
8k
views
Javascript why FOR IN is a bad practice? [duplicate]
Possible Duplicate:
JavaScript “For …in” with Arrays
People always tell me that using FOR IN is a bad practice, please could you tell me why? And why is better to use for with i?...
11
votes
3
answers
2k
views
Javascript for ... in loop with Object.prototype and Array.prototype properties [duplicate]
I am reading MDN docs for better understanding javascript. This is an excerpt from there
Object.prototype.objCustom = function() {};
Array.prototype.arrCustom = function() {};
let iterable = [3, ...
9
votes
3
answers
5k
views
Looping through a JSON Array gives "undefined" results [duplicate]
I have a JSON String being parsed (in a response var) from AJAX:
The JSON
{
"TheArray":[
{
"AlmostThere": {
"whatWeAreLookingFor":"Hello"
}
},
...
1
vote
5
answers
26k
views
Use for loop to print values in an array using JavaScript [duplicate]
I am learning JavaScript and now I am trying to run the following codes in Node to display the values in an array:
let array = [1, 2, 3];
for (let a in array) {
console.log(a);
}
I expect the ...
3
votes
1
answer
3k
views
check every element of an array [duplicate]
What is the most efficient way to check a certain condition on every element of an array and return false if one or more elements do not meet the condition, for example, I have this array for example
...
2
votes
3
answers
3k
views
JavaScript For-each/For-in loop changing element types [duplicate]
Possible Duplicate:
JavaScript “For …in” with Arrays
I'm trying to use the for-in syntax to loop through an array of numbers. Problem is, those numbers are getting converted to ...
6
votes
5
answers
552
views
Which for loop should I use for JavaScript arrays and objects? [duplicate]
I always use for (i=0; i<array.length; i++) when looping through arrays.
I always use for (var i in object) when looping through object properties.
I can't use for (i=0; ... ) for object ...
2
votes
2
answers
3k
views
What is wrong with for(let key in obj) in javascript? IDE warnings seem redundant [duplicate]
I use phpstorm and over the past half a year or so it started warning me about code like this:
for( let key in attachmentPaths ){
requestObject.formData.attachments.push( fs....
user avatar
user1037355
8
votes
1
answer
1k
views
Difference between a basic for-loop and a for-in-loop in JavaScript [duplicate]
Possible Duplicate:
JavaScript “For …in” with Arrays
In which situations using
for (var i = 0; i < array.length; i++)
is different from using
for (var i in array)
in ...
user avatar
user985358
0
votes
3
answers
1k
views
For.. in loop cannot set property of undefined [duplicate]
var table = document.querySelectorAll(".numbers");
function seppuku() {
for (let i in table) {
table[i].style.color = "red";
}
}
seppuku();
<div class="numbers">1</div>
&...
0
votes
3
answers
2k
views
Is it better to use reduce or a for loop for calculating the sum of values in an array? Why? [duplicate]
I have worked out two ways of calculating the same thing in my JavaScript. I just wonder which is more efficient in terms of memory usage and processing power:
AveragePL = netArray.reduce((sum,arr) =&...
0
votes
1
answer
661
views
for (x in y) VS for (i = 0; i < y.length; i++) Where x is an array of objects [duplicate]
Where y is an array of objects,
y = [
{property:"",property2:""},
{property:"",property2:""},
{property:"",property2:""},
{property:"",property2:""},
{property:"",property2:""}
]
...
1
vote
1
answer
1k
views
Why an empty array in javascript entering for loop? [duplicate]
I have following code snippet:
console.log('**1**',parentNode.child.length); //1
for(var ch in parentNode.child)
{
console.log('PTree root child',parentNode....