有没有一种方便的方法可以从这个数组中获取前n个索引:
var alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
如何将一个数组中的元素按照指定顺序存储到另一个数组中,比如说
alphabet2 = ['a','b','c'];
,而不需要使用循环来暴力解决?谢谢。有没有一种方便的方法可以从这个数组中获取前n个索引:
var alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
alphabet2 = ['a','b','c'];
,而不需要使用循环来暴力解决?谢谢。slice
方法:点此查看具体用法。> var alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
> alphabet.slice(0,3)
["a", "b", "c"]