js sort()方法改变原数组了怎么办
let arr = nums.sort((a, b) => a-b)
let arr1 = nums.map(item => item*item)
let target = arr1.sort((a, b) => a-b) // arr1被修改
let arr = nums.sort((a, b) => a-b)
let arr1 = nums.map(item => item*item)
let target = arr1.slice().sort((a, b) => a-b) // arr1不被修改
本文来自博客园,作者:叶子玉,转载请注明原文链接:https://www.cnblogs.com/knuzy/p/15938563.html