繁体   English   中英

遍历数组

[英]Loop through array

我想用 Javascript 编写如下代码。

我有一个从数组加载的下拉列表,如下所示:

apple 
orange
mango 
grapes

现在,如果用户从下拉列表中选择芒果,那么我应该将数组重置为:

mango
grapes
apple
orange

为什么不在循环中使用 Array 的 shift 和 push 方法。

例如。

var items = ["mango","grapes","apple"]
var selectedIndex = combo.selected.index
for( i = 0; i<selectedIndex ; i++){
items.push(items.shift())
}
combo.items = items

我不是日常 javascript 程序员,所以这只是一个想法。

暂无
暂无

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

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