📅  最后修改于: 2022-03-11 15:02:24.695000             🧑  作者: Mango
// 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)); // []