Skip to content
Advertisement

How to get the position information of a value of an array inside loop

I need to get the information of a position of an array inside the loop.

I’ve two variables.

JavaScript

So, the array would be look like this according to the value of i (in loop):

enter image description here

Now, I’ve to produce an array of information.

JavaScript

Detailed architecture of this is here:

enter image description here

I wan’t to prepare this positions array differently according to the position information.

You may ask me what I’ve tried. I actually doing it custom code. Like if(i=7){//do operation}, I mean totally humanize code. This is getting very weird. I think there has a way to do this dynamically.

Please help. Thanks in advance.

Advertisement

Answer

Hard-coding the output based on i is not a viable solution. The property values you are looking to output can be obtained through the use of the Modulo operator (%) and division:

JavaScript

For further information see the following MDN links:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement