Lets say I have:
var array = [0,1,2,3,4,5,6,7,8,9]
var itemsToExtract = 5
var startindex = 7
var direction = "forward"
I want to be able to do:
array.someMethod(startindex, itemsToExtract, direction)
I also want it to work backwards, if I set direction to "backward" (slicing from right to left).
I wasnt too lazy and tried something already, see here: http://jsfiddle.net/MkNrr/
I am looking for something "tidier" if there is, also is there a name for this method, is it a known problem?
Background: I am trying to build a sequential pre image loader (load one image(src) after the other) for use in an image gallery. Maybe even such a libary already exists?
以上就是Extract x items from array (slice) but continue from beginning if end is reached的详细内容，更多请关注web前端其它相关文章！