F
F
Faha19982016-04-12 16:20:03
JavaScript
Faha1998, 2016-04-12 16:20:03

How to put a limit on the index of an array in a loop?

there is an array
p = [....];
There is such a code

for(b=0;b<p.length;b++){
  var y = p[b];
  if(y <= ?? && y > 0){
    d++
  }
}

If I put just p[1] then it will check it with the value corresponding to this
index

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2016-04-12
@zolt85

determine the desired index, and put it instead of p.length in the loop condition

D
Daniil Sorokin, 2016-04-12
@DanSorokin

Write in the condition a restriction not on the value of the array cell, but on the index. That is, if( b <= 1 )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question