3

有没有一种方便的方法可以从这个数组中获取前 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'];不必用循环蛮力?谢谢

4

1 回答 1

4

使用方法_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"]
于 2012-08-02T16:59:11.847 回答