获取数组的前n个元素

JavaScript

const firstN = (arr, n) => arr.slice(0, n)

Examples

firstN(['a', 'b', 'c', 'd'], 2) // ['a', 'b']

posted on 2022-09-07 09:49  小馬過河﹎  阅读(39)  评论(0)    收藏  举报

导航