JavaScript数组:获取“范围"的项目 [英] JavaScript Array: get "range" of items
本文介绍了JavaScript数组:获取“范围"的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
JavaScript中是否有等效于ruby的 array [n..m]
?
Is there an equivalent for ruby's array[n..m]
in JavaScript?
例如:
>> a = ['a','b','c','d','e','f','g']
>> a[0..2]
=> ['a','b','c']
谢谢
推荐答案
使用 最后一个索引是非包容性的;要模仿红宝石的行为,您必须增加 end
值.所以我想 slice
的行为更像是ruby中的 a [m ... n]
.
The last index is non-inclusive; to mimic ruby's behavior you have to increment the end
value. So I guess slice
behaves more like a[m...n]
in ruby.
这篇关于JavaScript数组:获取“范围"的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文