Note that there are some explanatory texts on larger screens.

plurals
  1. POpass to function: incremented integer inside array or set reset array with ternary operator or a custom function
    primarykey
    data
    text
    <p>I have several arrays (in this example 8) holding information ("images adresses"):</p> <pre><code>var arr_1 = ["img1.jpg","img2.jpg","img3.jpg"]; var arr_2 = ["dis1.jpg","dis2.jpg","dis3.jpg","dis4.jpg","dis5.jpg","dis6.jpg"]; ... var arr_8 = ["rre.jpg","rre2.jpg","ree222.jpg","s4.jpg"]; </code></pre> <p>Now I need to pass to different functions the value of each array, as I would need a Counter for each array I have made an integer array of size 8 defined as:</p> <pre><code>var indexes = new Array(8); var counter = 0; for (counter=0; counter&lt;8; counter++){ indexes[counter]=0; } </code></pre> <p>so each entry will hold a number that will be a counter </p> <pre><code>indexes[0] represents the counter of array_1 indexes[1] represents the counter of array_2 ... indexes[7] represents the counter of array_8 </code></pre> <p>so to pass the value to a function I am doing something like</p> <pre><code>myfunction("MyID" , arr_1[indexes[0]++]); myfunction("MyIDtr" , arr_2[indexes[1]++]); myfunction("MyIDfoo" , arr_3[indexes[2]++]); ... myfunction("MyIDroot", arr_8[indexes[7]++]); </code></pre> <p>myfunction receives the id and a number representing a counter and tell corresponding array wich image adress it should take.</p> <p>Now, How can I do something like</p> <pre><code>if(indexes[0] &lt; arr_1.length){ indexes[0]++ }else indexes[0] = 0; </code></pre> <p>inside the call of my function?</p> <pre><code>myfunction("MyID" , logic ); </code></pre> <p>Is it neccesary to create a function or could it be done using ternary operator? If so how would look like the ternary expression?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload