Answer the question
In order to leave comments, you need to log in
What is the best way to traverse an array without going beyond its limits?
I'm asking for help in finding the best option for this situation.
There is a certain section of "spherical code in a vacuum":
var Arr = [][];
Arr.length = 100;
for(var i=0; i<100; i++) {
for(var j=0; j<100; j++) {
if(Arr[i + 10][j + 10] === 1) {
// что-то произойдёт
}
}
}
Answer the question
In order to leave comments, you need to log in
Why "heaps"? You just need to check if there is:
In general, you can set this 100 (it doesn’t come from nowhere?) via:var s = Math.min(100, Arr.length);
Or add functionality using the forEach method . There are indexes and everything else. Well, if you access an array element, no one will check for its existence for you.
the array must have a length property. And if you don’t need indexes i, j to death, then try using foreach loops
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question