📜  如何在javascript代码示例中使用从开头获取的n个元素创建数组切片

📅  最后修改于: 2022-03-11 15:02:24.695000             🧑  作者: Mango

代码示例1
// how to create a slice of the array with n elements taken from the beginning in javascript
const take = (arr, n) => arr.slice(0, n);
console.log(take([1, 2, 3], 2)); // [1, 2]
console.log(take([1, 2, 3], 0)); // []