假设我有一个列表,我想使用映射函数向其中添加一些值:
const arr = [1, 2, 3, 4, 5];
const anotherArr = [];
Run Code Online (Sandbox Code Playgroud)
我使用函数式方法来做到这一点:
arr.map((item) => anotherArr.push(item));
Run Code Online (Sandbox Code Playgroud)
这是一个反模式/错误的逻辑——也就是说,不使用映射操作返回值做任何事情?这方面有什么好的资源吗?
(我知道这个逻辑很愚蠢,我可以复制列表 - 这不是我的问题的重点)