在这个交互式演练场中探索和试验 es-toolkit 函数。从函数列表选择一个函数查看实时示例,或者编写你自己的代码。
import { chunk, groupBy, uniq } from 'es-toolkit'; // ============================================ // es-toolkit Playground // Try any function from the function list! // ============================================ // chunk(arr, size) // Splits an array into smaller arrays of the given size. const chunked = chunk([1, 2, 3, 4, 5, 6], 2); console.log('chunk:', chunked); // [[1, 2], [3, 4], [5, 6]] // uniq(arr) // Returns a new array with duplicates removed. const unique = uniq([1, 2, 2, 3, 3, 3]); console.log('uniq:', unique); // [1, 2, 3] // groupBy(arr, fn) // Groups array elements by a key returned from the callback. const grouped = groupBy( [ { name: 'Alice', age: 25 }, { name: 'Bob', age: 30 }, { name: 'Charlie', age: 25 }, ], item => item.age, ); console.log('groupBy:', grouped);

