简体   繁体   English

接下来获取数组中的所有项目

[英]Get next all items in array

I have an array of items. 我有一系列物品。

var array = [box1, box2, box3, box4];

when item is box1 , i need to get box2, box3, box4 . 当item为box1时 ,我需要获取box2,box3,box4

when item is box2 , get box3, box4 当item为box2时 ,获取box3,box4

how to get next all items with jquery? 如何使用jQuery获取下一个所有项目?

Sure, you don't need jquery though. 当然,您不需要jquery。 Just use Array.slice to get everything from supplied index to the end: 只需使用Array.slice即可获取从提供的索引到末尾的所有内容:

var x = [1, 2, 3, 4];
console.log(x.slice(1)); // [2, 3, 4]
console.log(x.slice(2)); // [3, 4];

You don't need jQuery to do that: 您不需要jQuery来做到这一点:

var array = [box1, box2, box3, box4];

for (var i = 0; i < box.length; i++){

     var 
         box1 = array[i],
         box2 = array[i + 1],
         box3 = array[i + 2],
         box4 = array[i + 3];

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM