Javascript 数组中有哪些方法可以改变自身,哪些不可以?
参考答案
改变原数组(mutating)
push、pop、shift、unshift、splice、sort、reverse、fill、copyWithin
不改变原数组(返回新值/新数组)
map、filter、reduce、forEach、concat、slice、join、indexOf、includes、find、some、every、flat、flatMap、keys/values/entries
备注
splice 修改原数组,slice 返回副本;sort/reverse 原地修改,需不可变时先 slice() 或 toSorted。