数组方法

课程:Javascript · 编程练习

JavaScript编程练习 - 数组方法

练习内容

// 使用数组的高阶函数\nconst numbers = [1, 2, 3, 4, 5];\n\n// 映射:创建平方数数组\nconst squares = numbers.map(x => x ** 2);\n\n// 过滤:筛选偶数\nconst evens = numbers.filter(x => x % 2 === 0);\n\nconsole.log(`原数组: ${numbers