Assume that I have a dynamic array that is contained within many different strings of population on page loads: I have a function that is called every event (we call a click) which is required to get 3 strings of the array continuously, while remembering that At which price it was left, last time it was called. Therefore: The first time the function is called, it gives returns: It is called, it gives returns: and so on ... code me Not required, instead of the click event or callback function, a code for the function that will generate extraction every time and bring it back. Something simple like being able to call: on each callback and to bring it back to the desired data. What if the array ends? Start from the beginning? You can do something like this: Edit: Added . and then If the number of elements is not divisible by number, then this can give you less element in "final" extraction, the next call from the extracted elements Will start You can also modify it that it wraps around and takes the element from the beginning so that it can always return as many elements you specify. Context :
string1, string2, string3
string4, string5, string6
arr.runExtraction ();
function get_iterator (value, step, start) {steps = steps} 1; Var start = start || 0, max = values.length; Return function () {var end = current + steps, end = end> Maximum? Maximum: end, t = value Sali (current, end); Current = end% max; // or if you do not want to wrap around: // current = end; Return T; }}
Start parameter. As
current
as
values.length ,
splice The empty table will return if you do not wrap around.
Slice will not change the original array using
var extract = get_iterator (arr, 3); Var arr1 = Remove (); // gives you the first three elements var arr2 = extract; // gives you the next three elements.
Comments
Post a Comment